开发者

Dynamically change font size in Android

I want to support font resizing with an entry in Preferences (where the user picks among given font size options) or by using a gesture (flinging up/down) as used in popular e-book reader applications such as Aldiko. Flinging up and down along right side of the screen triggered brightness ch开发者_如何学Cange in Aldiko.

How can I implement this type of dynamic property change? Are there any implementation differences for this in 1.6 and 2.0+ ? Do I have to have different themes pre-configured with different font sizes?


Actually, you do it like that:

TextView tv=new TextView(this);

    //either:
    tv.setTextAppearance(this, R.style.textStyle1); //some style you have set up


    ///or: 
    tv.setTextSize(16);
    tv.setTextColor(R.color.myred); //some color you set up

so not a static call to TextView you need an isntance of textview.


Try this:

tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜