Skip to content Skip to sidebar Skip to footer

Android: How To Change App Font Size From Code

I have a requirement where I need to change the application font size based on user provided values. How can I do that? I have googled but it seems that this can only be done is fr

Solution 1:

Call setTextSize() on each TextView (or other widgets that inherit from TextView, such as Button).

Solution 2:

The only way I can think of is to extend TextView and make them check a global textSize variable on every onDraw(). It should not add too much overhead to the drawing.

Solution 3:

It seems like I cant change app font size and I have to change font size for individual element seperateley.

Solution 4:

You must create file styles.xml in values and in this file:

<resources><style><itemname="android:textSize">20sp</item></style></resources>

Solution 5:

Define a style in styles.xml file under the values directory and customize whatever you want. I'm using textSize 11sp

<stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item><itemname="android:textColor">@color/textColorTitle</item><itemname="android:textSize">11sp</item><itemname="android:textColorSecondary">@color/colorAccent</item><itemname="buttonStyle">@style/ButtonStyle</item></style>

In the menifest file apply to your activities like

<activity
            android:name=".view.activities.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme" />

Post a Comment for "Android: How To Change App Font Size From Code"