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)
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.
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);
The Component background can be tricky. Some things to consider:
If the style has an image border defined, then that will take precedence over any other background settings.
If the style has an image background, then that will take precedence over BgColor()
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);
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);
Related
I want to apply RoundBorder style to MultiButton Line2 label when horizontal layout is set to true but calling mb.setHorizontalLayout(true); but I can't because LineX labels are not accessible outside the MultiButton.
I know that I can create curved border using theme designer and applying the uiid to the label using any of the setUIIDLineX() method but I don't want to use it because it didn't give me what I want in some device pixel density.
Is there any other way to style MultiButton internal components(Labels) through code?
Again, why is it that LineX labels are not exposed like icon label?
Exposing the LineX labels will equally enable developers to set icons for the individual labels depending on what the developer want to accomplish.
Thanks.
No one asked for that so we didn't add such getters. You can file an RFE for that or submit a pull request which will probably be quicker.
Notice you can style the round border in the current version of the designer so you can use a the UIID's to set the round border too.
I'm getting the hang of using themes to change my app's look and feel, but there are still a few mysteries. Right now, in the SocialBoo theme, the button to show the overflow menu is way too small, even though it's the right size in any other theme. Also, the overflow menu pops up with a nice animation on the other themes, but not in the SocialBoo theme. Can anyone tell me how to modify the theme to fix the size of the overflow button and specify an animation for the overflow menu?
SocialBoo is a pretty old demo that still uses the old GUI builder. We are slowly migrating away to the new GUI builder which was slated for the 3.4 release but is currently still considered beta status.
The new GUI builder standardizes on Toolbar which didn't exist when we developed the old GUI builder.
The icons for overflow/side menu can be customized via theme constants specifically sideMenuImage and menuImage.
I was able to partly fix this in code like this:
Hashtable<Object, Object> newThemeProps = new Hashtable<>();
// I need to start these with #, which tells the addThemeProps() method
// that these are theme constants, not theme properties.
// (The # character gets stripped out.)
newThemeProps.put("#menuTransitionIn", "bubble");
newThemeProps.put("#menuTransitionOut", "fade");
UIManager.getInstance().addThemeProps(newThemeProps);
This gave me the animations I wanted. I still don't know how to change this in the resource file.
As for the buttons, I fixed this in the Resource Editor by opening the TitleCommand style and setting the Background Image type to [empty] in the "..." button. This didn't improve the size of the button, but it removed the too-small button image, so it looks more professional. Here's what it looks like before the fix:
This is after the fix:
(Yeah, I added another item to the menu, too.)
It retrospect, I could probably have just checked the Derive button in the Background Image tab.
I also changed the TitleCommand foreground color to white (not shown), because the black buttons were practically invisible.
Finally, I changed the FontImage Icons to white with this piece of code:
/**
* The icon created by this method gets passed to the Command constructor.
*
* #param icon The FontImage constant for the desired icon
* #return The icon as an Image.
*/
#Nullable
public static Image createClearMaterialIcon(char icon) {
materialIconStyle = UIManager.getInstance().getComponentStyle("TitleCommand");
// materialIconStyle.setBgTransparency(0, true);
if (icon == 0) {
return null;
} else {
return FontImage.createMaterial(icon, materialIconStyle);
}
}
The transparency of the style needs to be set to zero (transparent). This can be done using the setBgTransparency() call in the line that's commented out, or it can be done by setting the TitleCommand resource's transparency to 0 in the Color tab.
Thank you, Shai, for pointing me in the right direction.
I want a spanlabel show text like
codename one
and code is blue and bold, name is red and bold. How do I achieve this?
That isn't supported by SpanLabel. You can either use a BrowserComponent and style the entries or use several different labels in a FlowLayout Container thus giving each of them the ability to be styled on its own.
I am setting the background color of my Canvas as 'white'. However when I compare my canvas with a vendor application, their canvas is 'whiter', which is the color I want for my canvas too. I have looked at all the color choices available for canvas background color but nothing makes my canvas any whiter than it is. Any suggestions would be appreciated.
Simple solution:
Use one of the browser plugins to get the actual "white" color of their app.
One example of a color-picker is Chrome plus the ColorZilla extension:
https://chrome.google.com/webstore/detail/colorzilla/bhlhnicpbhignbdhedgjhgdocnmhomnp
Does anyone know what the background colour is for the jetpack theme??
http://www.silverlight.net/content/samples/sl4/themes/jetpack.html
We're using the theme, but I can't see that light silver background colour which has a gradient through it.
Actually if you create a new project based on the JetPack theme, you will see there is a user control called TiledBackground which does the repeating effect for you.
However, the dependency property ResourceUri of this user control is binding to a wrong image file by default, I believe, and that's why you only see a light colored background.
To have the same background as in the demo, you simply need to replace the image backgroundtexture.png in the Images folder with the image file that Joe has provided. Then in the MainPage.xaml, you need to make sure the SourceUri is binding to this image.
For example, I have replaced with Joe's image and still named it backgroundtexture.png, and my project name is JetPack.
<controls:TiledBackground SourceUri="/JetPack;component/Images/backgroundtexture.png" />
Then you should see the dark background as expected. :)
It's actually an image that is repeated. To get the same effect you'll have to write a custom control or effect that tiles the image. Here's the image.
And here's a sample of tiling an image.
http://nokola.com/blog/post/2009/12/22/Fast-Tile-Brush-in-Silverlight-And-Easiest-Way-to-Shader-Effects.aspx