2017-05-23 7 views
0

TextViewのサイズを共有設定で変更しています。私はコードを正しく設定していることを絶対に確信しているので、正しいかどうかは分かりません。私は、誰かが問題を認識し、それを修正してもらえるかどうか疑問に思っていました。 おかげフラグメント内の共有設定を使用してフォントサイズを変更する

prefsize = this.getActivity().getSharedPreferences(prefnamesize, Context.MODE_PRIVATE); 
tx.setTextSize(prefsize.getFloat(FONT_SIZE_KEY, 25)); 
+0

だからあなたの問題は何ですか?共有環境設定への書き込み方法も教えてください。 – Thomas

答えて

0

これは、この目的のために、右/ベストプラクティス

ストアすべてのテキストのサイズや値フォルダ

の「DP」やdimen.xmlの「SP」に関連したものではありません

dimen.xml

あなたのレイアウトファイルへ回の
<resources> 
    <dimen name="textSizeMedium">16sp</dimen> 
</resources> 

アクセスこの:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    ... 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textSize="@dimen/textSizeMedium" /> // <----- This is the way 

    ... 

</FrameLayout> 

またはJavaコードで動的に(活動)

tx.setTextSize(getResources().getDimension(R.dimen.textSizeMedium)); 

(フラグメント)

tx.setTextSize(getActivity().getResources().getDimension(R.dimen.textSizeMedium)); 
関連する問題