androidandroid-layouttextviewandroid-1.6-donut

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


Solution

  • 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.