簡體   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