I need to fix one problem.
In the Android Studio I am trying to use SharedPreferences and store the font type but there is something wrong with my code. Please help me out.
// Load Text Font start
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());
// Load Text Font end
//Font Buttons start
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();
}
});
When I click, the button font type changes in the text view but does not store.
I think that something is wrong here: editor.putInt("font", textExample.getTypeface().getStyle());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.