How to set a font to LabelField text in Blackberry?

前端 未结 2 854
情话喂你
情话喂你 2021-02-03 15:53

I don\'t know how to apply font style to a text in a LabelField in Blackberry.

2条回答
  •  野性不改
    2021-02-03 16:27

    Here's a post which has a ResponseLabelField that extends LabelField and shows how to set the font: http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=37988

    Here's a quick code snippet for you:

        LabelField displayLabel = new LabelField("Test", LabelField.FOCUSABLE)
        {
            protected void paintBackground(net.rim.device.api.ui.Graphics g)
            {
                g.clear();
                g.getColor();
                g.setColor(Color.CYAN);
                g.fillRect(0, 0, Display.getWidth(), Display.getHeight());
                g.setColor(Color.BLUE);               
            }
        };  
    
        FontFamily fontFamily[] = FontFamily.getFontFamilies();
        Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 8);
        displayLabel.setFont(font);
    

    Someone correct me if I'm wrong, but I believe different fonts are chosen by using a different index into the fontFamily array.

    EDIT: And here's a test app you can use to switch between fonts: http://blackberry-digger.blogspot.com/2009/04/how-to-change-fonts-in-blackberry.html

提交回复
热议问题