我想以编程方式将 UserSetting 中的文本大小设置为我的 textView;问题是当它随着 myTextView.setTextSize(18)
改变时,一旦我返回到我的 xml,它就会返回默认大小,我不想要那个,而是我想保留我自己的文本大小。
我的 TextView xml:
<TextView
android:id="@+id/MainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginTop="15dp"
android:lineSpacingExtra="3dp"
android:text="long_lorem_ipsum_2"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/grey_60"
android:layout_marginBottom="80dp"/>
最佳答案
使用 SharedPreferences 来保存你自己的 TextSize
在 SharedPreferences 中保存文本大小的代码:
SharedPreferences pref=getSharedPreferences("MyPref",MODE_PRIVATE);
SharedPreferences.Editor editor=pref.edit();
editor.putFloat(FONT_SIZE_KEY,textSize); // your textsize
editor.commit();
从 SharedPreferences 中获取 textsize 的值
SharedPreferences prefs=getSharedPreferences("MyPref", MODE_PRIVATE);
float fontsize=prefs.getFloat(FONT_SIZE_KEY, 12);
关于android - 覆盖 TextView 的文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53950004/