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: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"            

 

更多相关文章

  1. Android 5.0 Material 自定义Dialog 背景 字体大小颜色 ui组件颜
  2. IOS/Android 移动端原生及自定义控件开发集v0.1
  3. Android自定义控件——仿ios开关按钮
  4. 写了个android gif显示控件,很简单很方便,开源了
  5. android设置控件样式(边框颜色,圆角)和图片样式(圆角)
  6. Android下EditText中的字体不统一问题
  7. 一个让你掌握Android所有控件的Demo
  8. Android[初级教程]第一篇 Button控件和TextView控件

随机推荐

  1. install Android development environmen
  2. Android:EventBus向上向下传参
  3. Android打包编译流程
  4. Android之ToolBar项目封装,踩坑过河
  5. Android TextView内容设置超链接、颜色、
  6. 获取定位数据
  7. android网络连接总结
  8. Android调用系统相机onActivityResult返
  9. android notification 传值关键
  10. 实现Android立体翻页效果的工具类!