TextView控件的属性介绍:
1、android里面设置字体推荐使用sp作为单位,设置高度和宽度使用dp作为单位
2、TextView的颜色介绍:
改变字体的颜色: android:textColor="#00ff00"
改变局部字体的颜色:
第一种方法:
TextView tv=new TextView(this);
TextView tv=(TextView)findViewById(R.id.textview);
tv.setTex(Html.fromHtml("我们学习的android很久了"));//”很久了“这个几个字的字体颜色会变蓝
第二种方法:
TextView tv=new TextView(this);
TextView tv=(TextView)findViewById(R.id.textview);
string str=“this is my android application”;
SpannableStringBuilder style=new SpannableStringBuilder(str);//加载str
style.setSpan(new ForegroundColorSpan(Color.Red),1,5,Spannable.SPANNABLE.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(style);
3、TextView 的超链接
android:autolink 设置是否textview 是url链接/emal/电话号码/map时,文本显示为可点击的链接。可选值(none/web/emal/phone/map/all)
main.xml里面的代码:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:textColor="#00ff00"
android:autoLink="web"
/>
main.java里面的代码
TextView tv=new TextView(this);
TextView tv=(TextView)findViewById(R.id.textview);
tv.setText("我的电话号码是1325689898889"); 也可以main.xml里面直接设置android:text=“我的电话号码是1325689898889"
4、textView 跑马灯的效果
android:ellipsize设置字体过长时,该控件该如何显示,有如下属性可以设置:如:
(1)、 "start”:省略号显示在开头
(2)、"end”:省略号显示在结尾
(3)、"middle”:省略号显示在中间
(4)、"marquee":以跑马灯的方式显示
使用跑马灯显示必须有如下设置:
android:marqueeRepeateLimit在ellipseSize指定marquee的情况下,设置重复滚动的次数,当设置marquee_rorever 表示无限次
android:focusableInTouchMode:是否在触摸模式下获得焦点
android:focusable控件是否能获取焦点
例子: (android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever" )
以上是textView使用跑马灯必须使用的属性
TextView是一种用于显示字符串的控件,直接继承View,它还是EditText、Button两个组件的父类。
android:focusableInTouchMode="true"