Reputation: 710
I am trying to change the background color for a specific container with this line of code :
Container container = new Container(new BorderLayout());
container.getStyle().setBgColor(0x99CCCC);
but nothing happens, i used also repaint()
but also nothing. the same with setBgTransparency(0)
Upvotes: 4
Views: 1957
Reputation: 4716
The Component background can be tricky. Some things to consider:
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);
Upvotes: 2
Reputation: 159
In CodeNameOne three steps to have a gradient colored container: 1. getUnselectedstyle 2. setBackgroundType : that can be either : BACKGROUND_GRADIENT_LINEAR_HORIZONTAL BACKGROUND_GRADIENT_LINEAR_VERTICAL ...
setBackgroundGradientStartColor and EndColor (if you wish to have no gradient you should make same color for StartColor and EndColor)
Container Container1 = new Container();
Container1.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_GRADIENT_RADIAL);
Container1.getUnselectedStyle().setBackgroundGradientEndColor(0xFFBCCA);
Container1.getUnselectedStyle().setBackgroundGradientStartColor(0xFFBCCA);
Upvotes: 1
Reputation: 1907
setBgTransparency(0) make container to transparent so setBgTransparency to 255 to make it opaque . And hope the following codes will help you
Container container = new Container(new BorderLayout());
container.getStyle().setBgColor(0x99CCCC);
container.getStyle().setBgTransparency(255);
Upvotes: 3
Reputation: 615
If you want to format the container or change style of the container, then you just have to create UIID in designer for container, Here you can format background color, margin, padding, etc. So you just have to create UIID and apply it to specific container.
For example:-
Container container = new Container();
container.setUIID("Container_uiid_name");
and you achieve the expected output.
Upvotes: 2