【问题标题】:Can I select the some specific text from long string and perform action on selected text我可以从长字符串中选择一些特定的文本并对选定的文本执行操作吗
【发布时间】:2020-10-09 23:01:02
【问题描述】:

您可以查看此屏幕短 image 基本上我想在我的文本上应用不同的格式,我只想从长字符串中选择一些文本区域并应用粗体、下划线或对选定文本执行的一些其他操作。

【问题讨论】:

    标签: android-studio


    【解决方案1】:

    这是一种突出显示文本的方法。

        Spannable spannable = new SpannableString("A test message");
        spannable.setSpan(new BackgroundColorSpan(Color.YELLOW), {start_index), {end_index}, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    

    这里有一篇文章向您展示了如何使您的文本可选择以及如何获取开始和结束索引。

    Get Selected Text from TextView

    这是对使用 spannable 的参考,您可以使用它来找出对字符串的其余文本更改。有很多可用的选项。 https://developer.android.com/reference/android/text/style/BackgroundColorSpan

    【讨论】:

      猜你喜欢
      • 2011-03-17
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多