TextView控件使用小技巧
一、设置字体颜色的三种方法
1、android:textColor //直接设置整体文本颜色
2、利用Html标记
TextView tv= (TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml("时间<font color=blue>厉害,逃得出</font>黑洞,避不过轮回。"));
3、自定义一个style
SpannableStringBuilder style=new SpannableStringBuilder(str);
//下面括号里面分别是(颜色,起始位置,结束位置,一个常量)
style.setSpan(new ForegroundColorSpan(Color.RED), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.GREEN), 6, 21, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.BLUE), 21, 34, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(style);
二、跑马灯效果:
android:singleLine="true"
android:focusable="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
更多相关文章
- 解决h264readInt()值太大 以及 SPS和PPS的获取
- android 设置EditText和TextView不可见
- if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.....)
- Mono For Android(安卓)重要的类文件
- Android(安卓)log详解
- android Java代码设置textview的字体资源颜色
- 在Android(安卓)studio中使用viewpager创建出图片轮播效果
- android:theme 常用颜色colorPrimary,colorPrimaryDark等属性使
- android自定义TextView(一)