开发者

Dynamically change font size in Android

开发者 https://www.devze.com 2023-03-21 11:18 出处:网络
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

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

精彩评论

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

关注公众号