Search in sources :

Example 31 with BackgroundColorSpan

use of android.text.style.BackgroundColorSpan in project GwellDemo by dxsdyhm.

the class SensorActivity method setExplain.

private void setExplain() {
    String str = "遥控  传感器  特殊传感器  已学习";
    int romStart = str.indexOf("遥控");
    int romEend = romStart + "遥控".length();
    int chStart = str.indexOf("传感器");
    int chEend = chStart + "传感器".length();
    int spStart = str.indexOf("特殊传感器");
    int spEend = spStart + "特殊传感器".length();
    int selStart = str.indexOf("已学习");
    int selEend = selStart + "已学习".length();
    SpannableStringBuilder style = new SpannableStringBuilder(str);
    style.setSpan(new BackgroundColorSpan(Color.CYAN), romStart, romEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    style.setSpan(new BackgroundColorSpan(Color.GREEN), chStart, chEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    style.setSpan(new BackgroundColorSpan(Color.YELLOW), spStart, spEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    style.setSpan(new BackgroundColorSpan(Color.RED), selStart, selEend, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tvExplain.setText(style);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan)

Aggregations

BackgroundColorSpan (android.text.style.BackgroundColorSpan)31 ForegroundColorSpan (android.text.style.ForegroundColorSpan)19 ImageSpan (android.text.style.ImageSpan)14 SpannableStringBuilder (android.text.SpannableStringBuilder)11 StrikethroughSpan (android.text.style.StrikethroughSpan)11 UnderlineSpan (android.text.style.UnderlineSpan)11 TextView (android.widget.TextView)11 SpannableString (android.text.SpannableString)7 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)6 RelativeSizeSpan (android.text.style.RelativeSizeSpan)6 StyleSpan (android.text.style.StyleSpan)6 View (android.view.View)6 Button (android.widget.Button)6 LinearLayout (android.widget.LinearLayout)6 Application (android.app.Application)5 CharacterStyle (android.text.style.CharacterStyle)5 SubscriptSpan (android.text.style.SubscriptSpan)5 SuggestionSpan (android.text.style.SuggestionSpan)5 SuperscriptSpan (android.text.style.SuperscriptSpan)5 TypefaceSpan (android.text.style.TypefaceSpan)5