【问题标题】:How to store the EditText style (Bold, Italic, Color, etc.) using Sharedpreferences如何使用 Sharedpreferences 存储 EditText 样式(粗体、斜体、颜色等)
【发布时间】:2019-03-26 04:55:30
【问题描述】:

请任何人告诉我 如何使用 SharedPreferencestext 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);

【问题讨论】:

    标签: android android-edittext styles sharedpreferences store


    【解决方案1】:
    SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); 
    
    Editor editor = pref.edit();
    
    editor.putString("edittext", "text of your edit text"); 
    
    editor.putString("style", "bold"); 
    
    editor.apply
    

    【讨论】:

    • 他怎么知道选中的文字是粗体的......不是斜体或常规的?
    • @AliAhmed 另一个问题
    • 请给我投票变成0,不知道为什么人们给我反对票
    • 我没有给你否定。
    • @AliAhmed 我知道,你之前说过,但你可以放弃我的投票,让这个归零
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多