【问题标题】:setStatus() in Blackberry黑莓中的 setStatus()
【发布时间】:2013-12-05 19:26:51
【问题描述】:

我想在 Blackberry 的屏幕底部和右侧添加一个 LabelField。在屏幕底部设置标签,

我用过,

this.setStatus(lbl_version);

这使得输出非常好,但是在 labelfield 后面,没有设置背景图像。标签设置在纯白色背景上。我想在背景图像以及屏幕底部设置标签。

请查看以下图片网址,您会有更好的想法。

提前致谢。请帮帮我。

http://i.stack.imgur.com/5UKv6.png

【问题讨论】:

    标签: blackberry blackberry-simulator blackberry-eclipse-plugin


    【解决方案1】:

    我会将此作为评论添加到 Nate 的答案中,但我没有足够的空间,我无法在评论中格式化代码。

    我认为 Nate 的解决方案有效,因为他使用的是纯色并且没有标题或横幅区域。当使用位图或渐变作为背景并且有标题或横幅时,我认为它不会起作用。

    要了解答案,您需要了解 MainScreen 中使用的管理器。据我了解,使用了许多经理。一 - 委托经理,用于整个屏幕。除此之外还有:

    1. 位于屏幕顶部的横幅管理器
    2. 标题经理位于横幅经理下
    3. 主要经理和
    4. 状态管理器,位于底部 屏幕。

    委托管理器将为所有其他管理器提供背景,如果它们是透明的。我的测试表明,横幅字段和状态字段的经理的背景是透明的。标题字段经理的背景不是 - 它是黑色的 - 但更改它似乎有问题。

    无论如何,在我的测试中,为了符合要求,您需要做的就是根据需要设置代理Manager的背景,并将MainManager的背景设置为透明。

    以下代码的设置方式我认为可以回答问题。但是,我还留下了一些注释掉的行,我建议您取消注释并注意效果。这很有趣(至少对于像我这样悲伤的人来说)。

    Background transparentBackground = BackgroundFactory.createSolidTransparentBackground(0, 0);
    Background gradientBackground = BackgroundFactory.createLinearGradientBackground(0X00909090, 0x00808080, 0x00E0E0E0, 0x00E8E8E8);
    getMainManager().setBackground(transparentBackground);
    getDelegate().setBackground(gradientBackground);
    // this is the same as this.setBackground(gradientBackground);
    
    LabelField banner = new LabelField("Hello Banner");
    // banner.setBackground(gradientBackground);
    setBanner(banner);
    
    // LabelField title = new LabelField("Hello Title");
    // title.setBackground(transparentBackground);
    // setTitle(title);
    // title.getManager().setBackground(transparentBackground);
    
    LabelField status = new LabelField("Hello Status");
    // status.setBackground(gradientBackground);
    setStatus(status);
    
    LabelField content = new LabelField("Hello Content", LabelField.FOCUSABLE);
    content.setBackground(transparentBackground);
    add(content);
    
    // Following just added so that focus can be moved off the content LabelField
    add(new NullField());
    

    最后,我可以推荐这篇文章来在 MainScreen 上阅读一些有趣的内容吗?
    MainScreen explained

    【讨论】:

      【解决方案2】:

      首先,确保您的LabelField 具有透明背景,然后您应该可以看到在包含它的MainScreen 上设置了什么背景。

      其次,我相信您需要在主屏幕本身及其嵌入的“主管理器”上设置(图像)背景,以便全屏显示相同的背景。

      例如,

      public class LabelScreen extends MainScreen {
      
         public LabelScreen() {
            super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
      
            Background bg = BackgroundFactory.createSolidBackground(Color.GREEN);
            getMainManager().setBackground(bg);
            setBackground(bg);
      
            LabelField status = new LabelField("Hello Status");
            status.setBackground(BackgroundFactory.createSolidTransparentBackground(0, 0));
            setStatus(status);
         }
      
      }
      

      注意:我上面的示例使用了纯色颜色背景,但对于图像背景应该以同样的方式工作。

      【讨论】:

        猜你喜欢
        • 2010-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-11
        • 1970-01-01
        相关资源
        最近更新 更多