简体   繁体   English

Android:哪种是根据用户偏好设置字体大小的最佳方法?

[英]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. 到目前为止,我们已经选择将在首选项屏幕中标记的字体大小分别分配给每个textview。

Let's put an example: 让我们举个例子:

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

In the onStart, we assign the fontsize like this: 在onStart中,我们这样分配fontsize:

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). 您可以利用这一事实,并使用sp(缩放点)根据此值设置字体大小。

<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/ 有关完整示例,请访问以下网站: http : //mobile.tutsplus.com/tutorials/android/android-user-interface-design-basic-font-sizes/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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