需要在res/color下 定义一个selector 我的代码如下
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#ff3333" android:state_selected="true"/>
<item android:color="#ff3333" android:state_pressed="true"/>
<item android:color="#333333"/>
</selector>
需要注意的是 顺序 很重要 如果把
<item android:color="#333333"/>
写在第一个的话 就不会有效果
textview里的文字局部变色的方法:
/**
* 文字局部变色
*/
public void agreementLink(TextView textView, String text) {
int start = text.indexOf(mContent);
if (start < 0)
textView.setText(text);
SpannableStringBuilder spannable = new SpannableStringBuilder(
text);// 用于可变字符串
ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#ff3333"));
spannable.setSpan(span, start, start + mContent.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannable);
}