Dynamically change font size in Android

faraday picture faraday · Jul 20, 2011 · Viewed 12.5k times · Source

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 change 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?

Answer

vallllll picture vallllll · Jul 20, 2011

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.