繁体   English   中英

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

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

我有一个偏好屏幕,用户可以在其中决定字体大小,因为我们为需要放大的视图问题的人优化了应用程序。

到目前为止,我们已经选择将在首选项屏幕中标记的字体大小分别分配给每个textview。

让我们举个例子:

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

在onStart中,我们这样分配fontsize:

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

哪个更好的方法?

有视力问题的人可能已经在整个系统上使用了较大的字体,可以在系统偏好设置中对其进行配置。

您可以利用这一事实,并使用sp(缩放点)根据此值设置字体大小。

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

有关完整示例,请访问以下网站: 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