TextView继承自View。用于显示文本。它有很多的子类,掌握其属性是非常重要的。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

TextView支持的XML属性及相关方法

XML属性

相关方法

说明

android:autoLink

setAutoLinkMask(int)

设置是否当文本为URL链接/email/电话号码/map时。文本显示为可点击的链接。

可选值(none/web/email/phone/map/all)

android:autoText

setKeyListener(KeyListener)

假设设置,将自己主动运行输入值的拼写纠正。

此处无效果,在显示输入法并输入的时候起作用

android:bufferType

setText(CharSequence,TextView.BufferType)

指定getText()方式取得的文本类别。选项editable 类似于StringBuilder可追加字符。   也就是说getText后可调用append方法设置文本内容。

spannable 则可在给定的字符区域使用样式,參见这里1、这里2。

android:capitalize

setKeyListener(KeyListener)

设置英文字母大写和小写类型。可选值(none不转换/sentences句子首字母大写/words单词首字母大写/characters每一个字母都大写)此处无效果。须要弹出输入法才干看得到,參见EditView此属性说明。

android:cursorVisible

setCursorVisible(boolean)

设定光标为显示/隐藏,默认显示。

android:digits

setKeyListener(KeyListener)

设置同意输入哪些字符。

如“.+-*/%\n()”

android:drawableBottom

setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

在text的下方输出一个drawable。如图片。假设指定一个颜色的话会把text的背景设为该颜色。而且同一时候和background使用时覆盖后者。

android:drawableEnd

setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int)

在text的结束处输出一个drawable。

android:drawableLeft

setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

在text的左边输出一个drawable。如图片。

android:drawablePadding

setCompoundDrawablePadding(int)

设置text与drawable(图片)的间隔。与drawableLeft、drawableRight、drawableTop、drawableBottom一起使用。可设置为负数,单独使用没有效果。

android:drawableRight

setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

在text的右边输出一个drawable,如图片。

android:drawableStart

setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int)

在text開始处输出一个drawable。如图片。

android:drawableTop

setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

在text的正上方输出一个drawable,如图片。

android:editable

设置是否可编辑。这里无效果,參见EditView。

android:editorExtras

setInputExtras(int)

设置文本的额外的输入数据。在EditView再讨论。

android:ellipsize

setEllipsize(TextUtils.TruncateAt)

设置当文字过长时,该控件该怎样显示。

有例如以下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)

android:ems

setEms(int)

设置该组件的宽度。以ms为单位

android:fontFamily

setTypeface(Typeface)

设置文本框内文本的字体

android:freezesText

setFreezesText(boolean)

设置保存文本的内容以及光标的位置

android:gravity

setGravity(int)

设置文本的对齐方式

android:height

setHeight(int)

设置文本看的高度,以px为单位

android:hint

setHint(int)

Text为空时显示的文字提示信息,可通过textColorHint设置提示信息的颜色。此属性在EditView中使用,可是这里也能够用。

android:imeActionId

setImeActionLabel(CharSequence,int)

设置IME动作ID。

android:imeActionLabel

setImeActionLabel(CharSequence,int)

设置IME动作标签。

android:imeOptions

setImeOptions(int)

附加功能,设置右下角IME动作与编辑框相关的动作,如actionDone右下角将显示一个“完毕”,而不设置默认是一个回车符号。这个在EditView中再具体说明,此处无用。

android:includeFontPadding

setIncludeFontPadding(boolean)

设置文本是否包括顶部和底部额外空白,默觉得true。

android:inputMethod

setKeyListener(KeyListener)

为文本指定输入法,须要输入法的全然限定名(完整的包名)。

android:inputType

setRawInputType(int)

设置文本的类型。用于帮助输入法显示合适的键盘类型。

android:lineSpacingExtra

setLineSpacing(float,float)

设置行间距。

android:lineSpacingMultiplier

setLineSpacing(float,float)

设置行间距的倍数。

android:lines

setLines(int)

设置文本默认行数。

android:linksClickable

setLinksClickable(boolean)

设置链接是否点击连接

android:marqueeRepeatLimit

setMarqueeRepeatLimit(int)

在ellipsize指定marquee的情况下,设置反复滚动的次数,当设置为marquee_forever时表示无限次。

android:maxEms

setMaxEms(int)

设置最大宽度(单位ms)

android:maxHeight

setMaxHeight(int)

设置最大高度(单位pixel)

android:maxLength

setFilters(InputFilter)

设置最大字符长度

android:maxLines

setMaxLines(int)

设置文本框最多占几行

android:maxWidth

setMaxWidth(int)

设置最大宽度(单位pixel)

android:minEms

setMinEms(int)

设置最小宽度(单位ms)

android:minHeight

setMinHeight(int)

设置最小高度(单位pixel)

android:minLines

setMinLines(int)

设置文本框最少占几行

android:minWidth

setMinWidth(int)

设置最小宽度(单位pixel)

android:numeric

setKeyListener(KeyListener)

设置关联的数字输入法,可选值(integer整数/signed带符号的数值/decimal带小数点的数值)

android:password

setTransformationMethod(TransformationMethod)

设置为password框。以小点显示文本

android:phoneNumber

setKeyListener(KeyListener)

设置仅仅接受电话号码

android:privateImeOptions

setPrivateImeOptions(String)

设置关联的输入法的私有选项

android:scrollHorizontally

setHorizontallyScrolling(boolean)

设置文本超出TextView的宽度的情况下。是否出现滚动条。

android:selectAllOnFocus

setSelectAllOnFocus(boolean)

假设文本是可选择的,设置是否获取焦点时自己主动选中全部文本。

android:shadowColor

setShadowLayer(float,float,float,int)

指定文本阴影的颜色,须要与shadowRadius一起使用。

android:shadowDx

setShadowLayer(float,float,float,int)

设置阴影横向坐标開始位置

android:shadowDy

setShadowLayer(float,float,float,int)

设置阴影纵向坐标開始位置

android:shadowRadius

setShadowLayer(float,float,float,int)

设置阴影的半径。设置为0.1就变成字体的颜色了。一般设置为3.0的效果比較好。

android:singleLine

setTransformationMethod(TransformationMethod)

设置单行显示。

设为true不换行。假设和layout_width一起使用,当文本不能所有显示时。后面用“…”来表示。

android:text

setText(CharSequence,TextView.BufferType)

设置显示文本

android:textAllCaps

setAllCaps(boolean)

设置是否将全部字母显示为大写

android:textAppearance

设置文本外观:颜色、字体、大小等

android:textColor

setTextColor(int)

设置文本颜色

android:textColorHighlight

setHighlightColor(int)

设置文本被选中时的颜色

android:textColorHint

setHintTextColor(int)

设置提示文本的颜色

android:textColorLink

setLinkTextColor(int)

设置连接的颜色

android:textIsSelectable

isTextSelectable()

当文本框不能够被编辑时。设置文本能否够被选中

android:textScaleX

setTextScaleX(float)

设置文字之间间隔

android:textSize

setTextSize(int,float)

设置文本字体大小

android:textStyle

setTypeface(Typeface)

设置字体风格[bold(粗体) , italic(斜体) , bolditalic(又粗又斜) ] 能够设置一个或多个。用“|”隔开

android:typeface

setTypeface(Typeface)

设置字体风格。必须是下面常量值之中的一个:normal , sans , serif , monospace(等宽字体) ]

android:width

setWidth(int)

设置文本区域的宽度(单位pixel)

Android学习笔记(17):文本框TextView类的更多相关文章

  1. Android学习笔记(三)Application类简介

    每次运行APP时,Application类都保持实例化状态.与Activity不同,配置改变不会导致应用程序重启.通过继承Application类,可以完成一下3项工作: · 对Android运行时广 ...

  2. Android学习笔记 TextSwitcher文本切换组件的使用

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  3. android学习笔记17——对话框(PopupWindow)

    PopupWindow ==> PopupWindow可创建类似对话框的窗口,使用其创建对话框窗口的操作步骤: 1.调用PopupWindow构造器构造PopupWindow对象: 2.调用Po ...

  4. Python 学习笔记17 文本 - 读写

    在我们的编程过程中,我们经常需要对文件进行读写操作. 在Python中,对文本的读写非常的方便,只需要简单的几行代码就可以实现. 我们首先新建一个文本文件"Text.txt", 里 ...

  5. Android学习笔记17:单项选择RadioButton和多项选择CheckBox的使用

    请参见 http://www.android100.org/html/201406/05/19495.html

  6. 【转】Pro Android学习笔记(十四):用户界面和控制(2):Text类控制

    目录(?)[-] TextView 例子1在XML中设置autoLink属性 例子2在代码中设置autoLink属性 EditText AutoCompleteTextView MultiAutoCo ...

  7. 【转】 Pro Android学习笔记(九二):AsyncTask(1):AsyncTask类

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 在Handler的学习系列中,学习了如何h ...

  8. 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge

    目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...

  9. Android学习笔记进阶17之LinearGradient

    具体的看一下博文:Android学习笔记进阶15之Shader渲染 package xiaosi.BitmapShader; import android.app.Activity; import a ...

随机推荐

  1. Websocket实现前后台通信,demo小测试

    新需求大概如下:用户登录系统,登录成功之后建立websocket连接,实现通信 总体思路:前端不是我负责,只是简单的做个功能,先实现登录,把用户标识存入HttpSeesion,再建立websocket ...

  2. 2015 多校赛 第四场 1010 (hdu 5336)

    Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...

  3. HDU 4474 Yet Another Multiple Problem BFS

    题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0  1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...

  4. S - New Year Transportation

    Problem description New Year is coming in Line World! In this world, there are n cells numbered by i ...

  5. A - Diverse Team

    Problem description There are n students in a school class, the rating of the i-th student on Codeho ...

  6. ES6 Promise(2)

    Promise的兴起,是因为异步方法调用中,往往会出现回调函数一环扣一环的情况.这种情况导致了回调金字塔的出现.不仅代码写起来费劲不美观,而且问题复杂的时候,阅读代码的人也难以理解. db.save( ...

  7. SQL优化--使用 EXISTS 代替 IN 和 inner join来选择正确的执行计划

    在使用Exists时,如果能正确使用,有时会提高查询速度: 1,使用Exists代替inner join 2,使用Exists代替 in 1,使用Exists代替inner join例子: 在一般写s ...

  8. 【Linux】Ubuntu输入法不能开机自启的解决方法

    操作系统:Ubuntu Kylin 16.10 自从操作系统安装了搜狗输入法以后,每次重启电脑都需要手动启动Fcitx,才能启动搜狗输入法.下面给大家介绍输入法开机自启的解决方法: 操作系统的用户家目 ...

  9. 【Linux】swap分区简介及空间增加方式

    swap分区简介 Swap分区在系统的物理内存不够用的时候,把硬盘空间中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存 ...

  10. Python 遍历目录

    代码: 1.递归使用遍历目录 import os def scanfile(path): filelist = os.listdir(path) allfile = [] for filename i ...