TextView控件的使用及总结

   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<font Color=red>很久了</font>"));//”很久了“这个几个字的字体颜色会变蓝

 

                                          第二种方法:

                                          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里面的代码:

                                 <TextView
                                         android:id="@+id/textview"
                                        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,它还是EditTextButton两个组件的父类。
                                           android:focusableInTouchMode="true"            

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值