To begin I've got an app with 2 activities. 1st is the main one. On the 2nd there are 3 checkboxes that are changing the typeface of textview in main activity (Bold, Italic and Underline). What I want to do is after closing and reopening app the text view has the typeface that was previously selected. Is there any way to store Typeface in shared preferences, or it can be done in some other way?
Thanks
UPDATE
This works (third approach from below answer)
boolean loadCheck1 = preferences.getBoolean("checked1", false);
if (loadCheck1) {
tx.setTypeface(tx.getTypeface(), Typeface.BOLD);
} else {
tx.setTypeface(null, Typeface.NORMAL);
}
boolean loadCheck2 = preferences.getBoolean("checked2", false);
if (loadCheck2) {
tx.setTypeface(tx.getTypeface(), Typeface.ITALIC);
} else {
tx.setTypeface(null, Typeface.NORMAL);
}
boolean loadCheck3 = preferences.getBoolean("checked3", false);
if (loadCheck3){
tx.setPaintFlags(tx.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
} else {
tx.setPaintFlags(tx.getPaintFlags() & (~Paint.UNDERLINE_TEXT_FLAG));
}
But there is a problem with Typeface Bold. It even if the checkbox1 is checked Bold is not appearing. It is really strange, cause every single If is made in the same way. In addition if I'll change the order (for example loadcheck2, loadcheck3, loadcheck1) then Italic is not appearing.