开发者

How to change Background of HorizontalFieldManager

I want to set the Background of HorizontalFieldManager. The sample code I've been searching is setting the background using Gradient for the main screen background.

 //create gradient linear for background
 this.getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(0x0099CCFF,
                            0x0099CCFF,0x00336699,0x00336699)
                        );

Then I try to use the same pattern to set background to HorizontalFieldManager, since it have this method. But it won't work. Here's the code

            HorizontalFieldManager hManager = new HorizontalFieldManager();

    Bitmap bitmapImage = null;

    bitmapImage = Bitmap.getBitmapResource("img/home.png");
    tabHome = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
            | BitmapField.HIGHLIGHT_FOCUS);

    bitmapImage = Bitmap.getBitmapResource("img/in.png");
    tabCheckInOut = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
            | BitmapField.HIGHLIGHT_FOCUS);

    bitmapImage = Bitmap.getBitmapResource("img/barcode.png");
    tabBarcode = new BitmapField(b开发者_运维技巧itmapImage, BitmapField.FOCUSABLE
            | BitmapField.HIGHLIGHT_FOCUS);

    bitmapImage = Bitmap.getBitmapResource("img/options.png");
    tabOptions = new BitmapField(bitmapImage, BitmapField.FOCUSABLE
            | BitmapField.HIGHLIGHT_FOCUS);

    tabHome.setFocusListener(this);
    tabCheckInOut.setFocusListener(this);
    tabBarcode.setFocusListener(this);
    tabOptions.setFocusListener(this);

    Background topBack = BackgroundFactory.createSolidBackground(0x00606A85);
    hManager.setBackground(topBack);

    hManager.add(tabHome);
    hManager.add(tabCheckInOut);
    hManager.add(tabBarcode);
    hManager.add(tabOptions);

    add(hManager);

I'm using HorizontalFieldManager and add 4 BitmapField, then I using BackgroundFactory to create solidBackground, and set it to the manager but when I run it, the background color does not apply. The gradient example work well. Is there anything that I'm missing? Please help me.

Thanks


After doing some deep web search. Here's the answer guys

HorizontalFieldManager manager = new HorizontalFieldManager()
{
    public void paint(Graphics graphics)
    {
        graphics.setBackgroundColor(0x000000FF);//blue
        graphics.clear();
        super.paint(graphics);
    }
};

UPDATE: You must only use Web Color such as 0x006699FF should work but 0x00606A85 would not work. if you want a specific color, i recommend you using bitmap.

UPDATE: Another solution

 HorizontalFieldManager manager = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
 manager.setBackground(BackgroundFactory.BackgroundFactory
            .createSolidBackground(0x00cccccc));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜