[英]Android Studio SharedPreferences and Font Style
我需要解決一個問題。
在 Android Studio 中,我嘗試使用 SharedPreferences 並存儲字體類型,但我的代碼有問題。 請幫幫我。
// 加載文本字體開始
SharedPreferences myTextFont = this.getSharedPreferences("MyTextFont", MODE_PRIVATE);
textFont = myTextFont.getInt("font", textExample.getTypeface().getStyle());
textExample.setTypeface(textExample.getTypeface());
textView3.setTypeface(textExample.getTypeface(), textExample.getTypeface().getStyle());
// 加載文本字體結尾
//字體按鈕開始
final Typeface typeface1 = ResourcesCompat.getFont(this,R.font.mkhatvruli);
type_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textExample.setTypeface(typeface1);
SharedPreferences myTextFont = getSharedPreferences("MyTextFont", MODE_PRIVATE);
SharedPreferences.Editor editor = myTextFont.edit();
editor.putInt("font", textExample.getTypeface().getStyle());
editor.commit();
}
});
當我單擊時,按鈕字體類型在文本視圖中更改但不存儲。
我認為這里出了點問題: editor.putInt("font", textExample.getTypeface().getStyle());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.