简体   繁体   中英

How to set font size globally and managed it by user

I want user to use SeekBar to choose the font size and apply it to whole app. I don't want to extend base classes eg TextView. I'm thinking something like in styles.xml set font size.

<item name="android:textSize">X</item>

Where "X" is a font size load from SharedPreferences. Is this even possibile? Also I want that text will change dynamical in app. So if user select with SeekBar font size to eg 20dp. It will change instantly. I found this . But there is exemple with predefined font size and this is not I'm looking for.

No, you can't dynamically change values from resource files. This is how I would do it:

  1. Store the font size selected by the user in SharedPreferences .
  2. In every class, load the value from the SharedPreferences and apply it to all TextViews

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