第一个效果:分别改变一行字不同颜色
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText(Html.fromHtml("是当放<font color=blue>十分路口时对方是</font>的法律是地方"));
或者用下面这个效果:
TextView tv = (TextView) findViewById(R.id.tv);
String str = "欢迎大家收看《android开发从零开始》系列书籍,感谢大家的支持。";
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);
第二个效果:在xml中设置超链接
<TextView android:id="@+id/tv"
android:autoLink="all"//可以根据不同要求设置不同的链接
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="欢迎大家收看《android开发从零开始》系列书籍,感谢大家的支持。\n博客地址:http://hao123.com\n我的电话:13225124261" />
第三个效果:跑马灯
<TextView android:id="@+id/tv1"
android:autoLink="all"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#00FF00"
android:focusable="true"
android:focusableInTouchMode="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:textSize="20sp"
android:text="欢迎大家收看《android开发从零开始》系列书籍,感谢大家的支持。博客地址:http://hao123.com.我的电话:13425004461" />