如何使用Sharedpreferences存储EditText样式(粗体,斜体,颜色等)

时间:2018-10-22 07:02:02

标签: android android-edittext styles sharedpreferences store

请任何人告诉我 如何使用 SharedPreferences text selected保存在EditText中(粗体,斜体,颜色等)。

这是我的代码:

int selectionStart = editTxt.getSelectionStart();    
int selectionEnd = editTxt.getSelectionEnd();                                
SpannableStringBuilder  stringBuilder = (SpannableStringBuilder) editTxt.getText();   
TextAppearanceSpan styleRed_Bold = new TextAppearanceSpan(getBaseContext(), R.style.CustomStyle);                                             stringBuilder.setSpan(styleRed_Bold , selectionStart , selectionEnd , 0);

1 个答案:

答案 0 :(得分:0)

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); 

Editor editor = pref.edit();

editor.putString("edittext", "text of your edit text"); 

editor.putString("style", "bold"); 

editor.apply