質問

In the Resource Editor I created a Font having a size of 9, and it is proportional, plain and small. Then I created also some UIID which are based on this Font. Now I want to change programmatically the size of this Font under certain circumstance , that is when the height or width of the Display is bigger than a reference value. The new value of the Font size will be then based on the Display size , so it's dynamic. So how to change programmatically the Font size of a Font defined in the Resource Editor ?

役に立ちましたか?

解決

That was a hard thing. You can't change programmatically the size of a Resource Editor's Font. You will need to build a Font by code and apply to the app by the Style class. For example if you want to change the Fontof a Label, you must to create the Font, add it to a Style and add this to the Label using the Component method setSelectedStyle() or setPressedStyle(), there are so many methods....

他のヒント

A resource theme is a Hashtable. Create another font for larger devices e.g. "LargeFont" then just extract it from the theme and apply it to the hashtable e.g.:

Font f = res.get("LargeFont");
Enumeration e = myTheme.keys();
while(e.hasMoreElements() {
    String current = (String)e.nextElement();

    if(current.indexOf("font") > -1) {
         // add this to a list of keys to change, I'm not sure if you can change them during  iteration
    }
}

// for every key to change
myTheme.put(key, f);

Now you have a theme with large fonts.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top