简体   繁体   中英

Android: which is the best way to set the font size depending on user preferences?

I have a preference screen where users can decide the fontsize, as we optimize the app for people with view problems who need some magnification.

Until now, we have chosen to assign the fontsize marked in the preference screen to every textview individually.

Let's put an example:

 <TextView android:id="@+id/textexample"/>

In the onStart, we assign the fontsize like this:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int ifontsize = Integer.parseInt(prefs.getString(PreferencesActivity.KEY_FONT_SIZE, ""));
   textexample.setTextSize(ifontsize);

Which is a better method?

People with view problems probably use already a larger font for the whole system, configurable in the system prefs.

You could exploit this fact and set your font size according to this value by using sp (scalepoints).

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sample Text - 26sp"
android:textSize="26sp" />

For a full example visit this site: http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-basic-font-sizes/

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