【问题标题】:How can I change the background image of a field manager while focus change in BlackBerry Java如何在 BlackBerry Java 中更改焦点时更改现场经理的背景图像
【发布时间】:2012-12-30 14:25:14
【问题描述】:

我是黑莓新手,我是使用选项创建菜单的新手。每个选项都包含一个位图图像和标签。

这是第一个菜单项的代码:

hmf1_vfm1 = new VerticalFieldManager(Field.FIELD_HCENTER |          VErrticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.FIELD_HCENTER |   VerticalFieldManager.FOCUSABLE | Field.FOCUSABLE)
{
 boolean isFocus;
//Bitmap bmp1 = Bitmap.getBitmapResource("mnu_tile1.png");
protected void sublayout(int maxWidth, int maxHeight)
 {
super.sublayout(100,125);
setExtent(100,125);
 }

protected void paint(Graphics g) {
try
{
   //g.setBackgroundColor(0x504A4B);
   //g.drawBitmap(0, 0, bmp1.getWidth(), bmp1.getHeight(), bmp1, 0, 0);
                    g.clear();
    Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("mnu_tile1.png")); //mnu_tile1.png
                    this.setBackground(bg);
                    super.paint(g);
                }
                catch (IllegalArgumentException e) {
                    //SupportClass.showLog(TAG+" err 2 : "+e);
                }
            }

            protected void onFocus(int direction) {
                isFocus = true;
                super.onFocus(direction);
            }
            protected void onUnfocus() {
                isFocus = false;
                super.onUnfocus();
            }

            protected boolean navigationClick(int status, int time) {

                //SupportClass.showLog("New Order...navigationClick");
                return true;
            }
            public boolean isFocusable() {
                return true;
            }
            /*protected boolean touchEvent(net.rim.device.api.ui.TouchEvent message) {

                //SupportClass.showLog("New Order...touchEvent");
                return true;
            };*/
        };

位图和标签字段被添加到此 vfm。顺便说一下

BitmapField bfNO = new BitmapField(bmpNO,Field.FIELD_HCENTER | Field.FOCUSABLE)
        {
            protected boolean navigationClick(int status, int time) {
                SupportClass.showLog("bitmap...navigationClick");
                return true;
            }
            protected void paint(Graphics graphics) {
                //this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK,0));
                super.paint(graphics);
            }
        };

LabelField txtNO = new LabelField("New Order",LabelField.FIELD_HCENTER | Field.FOCUSABLE )
        {
            protected void paint(Graphics g) {
                g.setColor(Color.WHITE);
                //g.setBackgroundColor(0x00000000);
                super.paint(g);
            }
            protected boolean navigationClick(int status, int time) {
                SupportClass.showLog("lable...navigationClick");
                return true;
            }
        };
  • 我想聚焦包含图像和标签的垂直字段管理器,同时设置背景我看不到背景。我猜有些图层重叠在背景上。

  • 我还想将字段(蓝色背景)的选择器颜色更改为透明。

  • 请告诉我我犯了什么错误。

【问题讨论】:

  • 你检查过这里的PictureBackgroundButtonField.java吗...! stackoverflow.com/questions/8942225/…
  • 这是一年多以前提出的。如果 OP 仍然对回复感兴趣,请更新问题,我会提供一些帮助。否则,回答这个问题似乎没有任何价值,因为代码是具体的,我怀疑可以对此提出的一般观点已经在其他更好的问题中涵盖。

标签: blackberry blackberry-jde


【解决方案1】:

您好,请尝试使用 invalidate() 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多