【问题标题】:How to change Background of HorizontalFieldManager如何更改 Horizo​​ntalFieldManager 的背景
【发布时间】:2011-08-24 05:37:54
【问题描述】:

我想设置 Horizo​​ntalFieldManager 的背景。 我一直在搜索的示例代码是使用 Gradient 作为主屏幕背景设置背景。

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

然后我尝试使用相同的模式将背景设置为 Horizo​​ntalFieldManager,因为它有这个方法。但它不会起作用。这是代码

            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);

我使用Horizo​​ntalFieldManager并添加4个BitmapField,然后我使用BackgroundFactory创建solidBackground,并将其设置为管理器 但是当我运行它时,背景颜色不适用。渐变示例效果很好。有什么我想念的吗?请帮帮我。

谢谢

【问题讨论】:

  • 您可以发布您的解决方案有答案并接受它
  • 实际上,我会说您应该将您的解决方案发布为答案并接受它。
  • 您能否检查以下代码是否对您有帮助,我不确定... hfmthree = new Horizo​​ntalFieldManager(){ protected void paint(Graphics graphics) { graphics.setColor(Color.WHITE); super.paint(图形); } };

标签: blackberry java-me horizontalfieldmanager


【解决方案1】:

在进行了一些深度网络搜索之后。小伙伴们来看看答案

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

更新: 您只能使用 Web 颜色 比如 0x006699FF 应该可以 但 0x00606A85 不起作用。 如果你想要一个特定的颜色,我建议你使用位图。

更新: 另一种解决方案

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

【讨论】:

  • 我在构造函数中设置了 USE_ALL_WIDTH。 Horizo​​ntalFieldManager manager = new Horizo​​ntalFieldManager( USA_ALL_WIDTH ) ... 等
猜你喜欢
  • 2011-09-10
  • 2011-05-10
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
  • 2011-12-05
  • 2014-04-27
  • 1970-01-01
  • 2012-09-08
相关资源
最近更新 更多