我会将此作为评论添加到 Nate 的答案中,但我没有足够的空间,我无法在评论中格式化代码。
我认为 Nate 的解决方案有效,因为他使用的是纯色并且没有标题或横幅区域。当使用位图或渐变作为背景并且有标题或横幅时,我认为它不会起作用。
要了解答案,您需要了解 MainScreen 中使用的管理器。据我了解,使用了许多经理。一 - 委托经理,用于整个屏幕。除此之外还有:
- 位于屏幕顶部的横幅管理器
- 标题经理位于横幅经理下
- 主要经理和
- 状态管理器,位于底部
屏幕。
委托管理器将为所有其他管理器提供背景,如果它们是透明的。我的测试表明,横幅字段和状态字段的经理的背景是透明的。标题字段经理的背景不是 - 它是黑色的 - 但更改它似乎有问题。
无论如何,在我的测试中,为了符合要求,您需要做的就是根据需要设置代理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