textview 设置多个状态文字颜色
2016-12-06 10:18
417 查看
需要在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>
需要注意的是 顺序 很重要 如果把
写在第一个的话 就不会有效果
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);
}
<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);
}
相关文章推荐
- Android利用SpannableStringBuilder设置TextView中部分文字的颜色...
- 利用SpannableStringBuilder设置TextView中部分文字的颜色
- 同一TextView 上的文字设置不同的颜色,大小等
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android textview改变部分文字的颜色和string.xml中文字的替换及部分内容设置颜色、字体、超链接、图片
- SpannableString设置AndroidTextView改变颜色,文字大小,图文混排等等
- 同一个TextView中设置不同颜色与文字大小
- TextView 文字颜色设置的多种方法
- Android中TextView中的文字颜色设置setTextColor的用法
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- 设置TextView按下时变换文字颜色
- android TextView 设置部分文字背景色和文字颜色
- 最新历史版本 :android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- 最新历史版本 :android--设置TextView部分文字的颜色和背景(高亮显示)
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
- Android中为TextView中的部分文字设置颜色和点击事件
- TextView设置部分文字背景色和文字颜色
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法