简体   繁体   中英

Android. Change font color for whole app programaticcaly

I want to let user change the font size or color in android app under settings. I had an idea to make style, apply it to chosen elements and finally in code just change its value, but now I have no idea how to make it. My default style looks like this

 <style name="myTextStyle" parent="AppTheme">
     <item name="android:textColor">#FF0000</item>
     <item name="android:textSize">10sp</item>
 </style>

I don't know how to change the default theme/style of app programmatically. Plz help!

You can create different styles with different font colors. Then you can apply the style to activity based on user preferences (maybe stored in SharedPreferences).

public void onCreate(Bundle savedInstanceState) {

    setTheme(android.R.style.Theme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM