Android Spannable前景/后台在一起?

时间:2016-02-01 22:38:11

标签: android

我需要为EditText的一部分设置样式。我希望文本为白色,背景为灰色。看起来很简单,但它不是。

spanRange.setSpan(new BackgroundColorSpan(Color.GRAY), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanRange.setSpan(new ForegroundColorSpan(Color.WHITE), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

mCaptionET.setText(spanRange, TextView.BufferType.SPANNABLE);

但我得到的是绿色,而不是白色。

enter image description here

我需要做什么才能在灰色上制作白色?

1 个答案:

答案 0 :(得分:1)

由于您android:autoLink="web"上有TextView更改文字链接颜色,因此您必须添加android:textColorLink="@android:color/white"

或使用Java

mCaptionET.setLinkTextColor(color);