首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改HorizontalFieldManager的背景

如何更改HorizontalFieldManager的背景
EN

Stack Overflow用户
提问于 2011-05-12 23:22:29
回答 1查看 2.2K关注 0票数 0

我想设置HorizontalFieldManager的背景。我一直在搜索的示例代码是使用渐变为主屏幕背景设置背景。

代码语言:javascript
复制
 //create gradient linear for background
 this.getMainManager().setBackground(BackgroundFactory.createLinearGradientBackground(0x0099CCFF,
                            0x0099CCFF,0x00336699,0x00336699)
                        );

然后,我尝试使用相同的模式将背景设置为HorizontalFieldManager,因为它具有此方法。但它不会起作用。下面是代码

代码语言:javascript
复制
            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(bitmapImage, 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);

我使用HorizontalFieldManager并添加4个BitmapField,然后使用BackgroundFactory创建solidBackground,并将其设置为管理器,但当我运行它时,背景颜色不适用。渐变示例运行良好。我是不是漏掉了什么?请帮帮我。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-13 22:43:50

在做了一些深度网络搜索之后。这是答案,伙计们

代码语言:javascript
复制
HorizontalFieldManager manager = new HorizontalFieldManager()
{
    public void paint(Graphics graphics)
    {
        graphics.setBackgroundColor(0x000000FF);//blue
        graphics.clear();
        super.paint(graphics);
    }
};

更新:您必须只使用网页颜色,如0x006699FF应该可以工作,但0x00606A85将不能工作。如果你想要一种特定的颜色,我建议你使用位图。

更新:另一个解决方案

代码语言:javascript
复制
 HorizontalFieldManager manager = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
 manager.setBackground(BackgroundFactory.BackgroundFactory
            .createSolidBackground(0x00cccccc));
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5980366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档