我想在一个文本视图中有 2 个文本样式,所以我尝试
Spannable text = new SpannableString(pseudo + " " + "some text after that");
text.setSpan(new TextAppearanceSpan(mContext, R.style.PseudoStyle), 0, pseudo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new TextAppearanceSpan(mContext, R.style.TextStyle), pseudo.length() + 1, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.mText.setText(text);
Run Code Online (Sandbox Code Playgroud)
在这里你可以找到我的风格
<style name="PseudoStyle">
<item name="android:textAllCaps">true</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/pink_light</item>
</style>
<style name="TextStyle">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,只有 android:textColor 是适用的。
你能用这种方法帮助有其他风格吗?
谢谢