Blackberry - Setting LabelField background color

前端 未结 2 700
独厮守ぢ
独厮守ぢ 2020-12-17 05:19

I want to place several LabelFields with right-aligned text on a MainScreen with an alice blue background. Unfortunately I can\'t seem to figure out how to make that happen

相关标签:
2条回答
  • 2020-12-17 05:52

    Use

    new LabelField("",LabelField.USE_ALL_WIDTH | DrawStyle.RIGHT);
    

    without overriding the paint method of the LabelField.

    0 讨论(0)
  • 2020-12-17 06:08

    In versions <= 4.5 you can create VerticalFieldManager with overrided paint():

    class BGManager extends VerticalFieldManager {
        public BGManager() {
            super(USE_ALL_HEIGHT|USE_ALL_WIDTH);
        }
        public void paint(Graphics graphics)
        {
            graphics.setBackgroundColor(Color.DARKRED);
            graphics.clear();
            super.paint(graphics);
        }
    }
    

    Then use it on youre screen adding simple LabelField to it:

    class Scr extends MainScreen {
        BGManager manager = new BGManager();
        public Scr() {
            super();
            add(manager);       
            manager.add(new LabelField("Hello!", FIELD_RIGHT));
            manager.add(new LabelField("This is a test", FIELD_RIGHT));
        }
    }
    

    In versions >= 4.6 you can use setBackgroud() method for default screen manager:

    class Scr extends MainScreen {  
        public Scr() {
            super();
            VerticalFieldManager manager = 
                (VerticalFieldManager)getMainManager();
            manager.setBackground(
                BackgroundFactory.createSolidBackground(
                    Color.DARKRED));        
            manager.add(new LabelField("Hello!", FIELD_RIGHT));
            manager.add(new LabelField("This is a test", FIELD_RIGHT));
        }
    }
    

    See BB KB DB-00131 - How to - Change the background color of a screen

    0 讨论(0)
提交回复
热议问题