代号为一个容器背景颜色

时间:2017-04-24 08:42:27

标签: codenameone

我正在尝试使用以下代码行更改特定容器的背景颜色:

Container container = new Container(new BorderLayout());
container.getStyle().setBgColor(0x99CCCC);

但没有任何反应,我也用repaint()但也没有。与setBgTransparency(0)

相同

4 个答案:

答案 0 :(得分:2)

如果你想格式化容器或更改容器的样式,那么你只需要在设计器中为容器创建UIID,在这里你可以设置背景颜色,边距,填充等格式。所以你只需要创建UIID和将它应用于特定的容器。

例如: -

Container container = new Container();
container.setUIID("Container_uiid_name");

并达到预期的产量。

答案 1 :(得分:2)

The Component background can be tricky. Some things to consider:

  1. If the style has an image border defined, then that will take precedence over any other background settings.
  2. If the style has an image background, then that will take precedence over BgColor()
  3. If the style's BgTransparency() is set to 0 then it doesn't matter what bgcolor you set, you won't be able to see it.

So, to cover all bases, you might do something like:

myComponent.getAllStyles().setBorder(Border.createEmpty());
myComponent.getAllStyles().setBackgroundType(BACKGROUND_NONE);
myComponent.getAllStyles().setBgTransparency(255);
myComponent.getAllStyles().setBgColor(myColor);

Or, using the fluent API of the ComponentSelector class:

$(myComponent)
    .setBorder(Border.createEmpty())
    .setBackgroundType(BACKGROUND_NONE)
    .setBgTransparency(255)
    .setBgColor(myColor);

答案 2 :(得分:1)

setBgTransparency(0)使容器变为透明,使setBgTransparency为255以使其不透明。并希望以下代码可以帮助您

Container container = new Container(new BorderLayout());
container.getStyle().setBgColor(0x99CCCC);
container.getStyle().setBgTransparency(255);

答案 3 :(得分:1)

在CodeNameOne中有三个渐变色容器的步骤:  1. getUnselectedstyle  2. setBackgroundType:        可以是:        BACKGROUND_GRADIENT_LINEAR_HORIZONTAL        BACKGROUND_GRADIENT_LINEAR_VERTICAL ...

  1. setBackgroundGradientStartColor和EndColor (如果你想没有渐变,你应该为StartColor和EndColor制作相同的颜色)

                Container Container1 = new Container();
                Container1.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_GRADIENT_RADIAL);
                Container1.getUnselectedStyle().setBackgroundGradientEndColor(0xFFBCCA);
                Container1.getUnselectedStyle().setBackgroundGradientStartColor(0xFFBCCA);