TextView的API 中文文档
2015-09-05 17:52
441 查看
结构
java.lang.Object android.view.View android.widget.TextView
直接子类
Button, CheckedTextView, Chronometer, DigitalClock, EditText
间接子类
AutoCompleteTextView, CheckBox, CompoundButton, ExtractEditText,MultiAutoCompleteTextView, RadioButton, ToggleButton
XML属性
android:autoLink
设置是否当文本为URL链接、
map时,文本显示为可点击的链接。 可选值:
none,web,email,phone,map,all.其中
map目前只使用于美国的地址,默认为
none。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:autoLink="phone" android:text="18888888888"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:autoLink="web" android:text="http://www.126.com"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:autoLink="email" android:text="hello_world@126.com"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:autoLink="map" android:text="620 Eighth Avenue New York, NY 10018"/> </LinearLayout>
点选电话号码会自动切换到拨电话活动。
android:drawableXXX
android:drawableBottom在
text的下方输出一个
drawable。如果指定一个颜色的话会把
text的背景设为该颜色。 同时和
background使用时覆盖后者。
android:drawableLeft在
text的左边输出一个
drawable。
android:drawableRight在
text的右边输出一个
drawable。
android:drawableTop在
text的正上方输出一个
drawable。
android:drawablePadding设置
text与
drawable(图片)的间隔,与
drawableLeft、
drawableRight、
drawableTop、
drawableBottom一起使用,可设置为负数,单独使用没有效果。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:drawableTop="@drawable/ic_launcher" android:text="图片在我上方,padding未设置"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:drawableBottom="@drawable/ic_launcher" android:drawablePadding="10dp" android:text="图片在我下方,padding为10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:drawableLeft="@drawable/ic_launcher" android:drawablePadding="-5dp" android:text="图片在我左边,padding为-5dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:drawableLeft="@drawable/ic_launcher" android:text="图片在我左边,padding未设置"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="15dp" android:drawableRight="@drawable/ic_launcher" android:text="图片在我右边,padding为5dp" android:drawablePadding="5dp"/> </LinearLayout>
android:singleLine
设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如
android:text="test_singleLine" android:singleLine="true" android:layout_width="20dp"将只显示
t…。如果不设置
singleLine或者设置为
false, 文本将自动换行.
android:ellipsize
android:ellipsize设置当文字过长时,该控件该如何显示。有如下值设置:
start—–省略号显示在开头;
end——省略号显示在结尾;
middle—-省略号显示在中间;
marquee——以跑马灯的方式显示(动画横向移动)。
android:marqueeRepeatLimit在
ellipsize指定
marquee的情况下,设置重复滚动的次数, 当设置为
marquee_forever时表示无限次。若要出现走马灯效果,需要是单行,即
android:singleLine="true",且
android:focusable和
android:focusableInTouchMode属性为“true”。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="start" android:text="这是一个非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的字符串"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:paddingTop="10dp" android:ellipsize="middle" android:text="这是一个非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的字符串"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:paddingTop="10dp" android:focusable="true" android:clickable="true" android:focusableInTouchMode="true" android:ellipsize="end" android:text="这是一个非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的字符串"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:paddingTop="10dp" android:ellipsize="marquee" android:marqueeRepeatLimit="2" android:focusable="true" android:clickable="true" android:focusableInTouchMode="true" android:text="这是一个非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的字符串"/> </LinearLayout>
其他
属性名称 | 描述 |
---|---|
android:autoText | 如果设置,将自动执行输入值的拼写纠正。 此处无效果,在显示输入法并输入的时候起作用。 |
android:bufferType | 指定getText()方式取得的文本类别。 选项 editable类似于 StringBuilder可追加字符, 也就是说 getText后可调用 append方法设置文本内容。 spannable则可在给定的字符区域使用样式。 |
android:capitalize | 设置英文字母大写类型。此处无效果,需要弹出输入法才能看得到 |
android:cursorVisible | 设定光标为显示/隐藏,默认显示。 |
android:digits | 设置允许输入哪些字符。如“1234567890.+-*/%\n()” |
android:editable | 设置是否可编辑。这里无效果。 |
android:editorExtras | 设置文本的额外的输入数据。 |
android:freezesText | 设置保存文本的内容以及光标的位置。 |
android:gravity | 设置文本位置,如设置成center,文本将居中显示。 |
android:hint | Text为空时显示的文字提示信息,可通过 textColorHint设置提示信息的颜色。 此属性在EditView中使用,但是这里也可以用。 |
android:imeOptions | 附加功能,设置右下角IME动作与编辑框相关的动作, 如 actionDone右下角将显示一个“完成”,而不设置默认是一个回车符号。此处无用。 |
android:imeActionId | 设置IME动作 ID。 |
android:imeActionLabel | 设置IME动作标签。 |
android:includeFontPadding | 设置文本是否包含顶部和底部额外空白,默认为true。 |
android:inputMethod | 为文本指定输入法,需要完全限定名(完整的包名)。 例如: com.google.android.inputmethod.pinyin,但是这里报错找不到。 |
android:inputType | 设置文本的类型,用于帮助输入法显示合适的键盘类型。这里无效果。 |
android:linksClickable | 设置链接是否点击连接,即使设置了autoLink。 |
android:ems | 设置TextView的宽度为 N个字符的宽度。 |
android:maxEms | 设置TextView的宽度为最长为 N个字符的宽度。与 ems同时使用时覆盖 ems选项。 |
android:minEms | 设置TextView的宽度为最短为 N个字符的宽度。与 ems同时使用时覆盖 ems选项。 |
android:maxLength | 限制显示的文本长度,超出部分不显示。 |
android:lines | 设置文本的行数,设置两行就显示两行,即使第二行没有数据。 |
android:maxLines | 设置文本的最大显示行数,与width或者 layout_width结合使用, 超出部分自动换行,超出行数将不显示。 |
android:minLines | 设置文本的最小行数,与lines类似。 |
android:lineSpacingExtra | 设置行间距。 |
android:lineSpacingMultiplier | 设置行间距的倍数。如”1.2” |
android:numeric | 如果被设置,该TextView有一个数字输入法。此处无用, 设置后唯一效果是 TextView有点击效果。 |
android:password | 以小点”.”显示文本 |
android:phoneNumber | 设置为电话号码的输入方式。 |
android:privateImeOptions | 设置输入法选项,此处无用。 |
android:scrollHorizontally | 设置文本超出TextView的宽度的情况下,是否出现横拉条。 |
android:selectAllOnFocus | 如果文本是可选择的,让它获取焦点而不是将光标移动为文本的 开始位置或者末尾位置。 EditText中设置后无效果。 |
android:shadowColor | 指定文本阴影的颜色,需要与shadowRadius一起使用。 |
android:shadowDx | 设置阴影横向坐标开始位置。 |
android:shadowDy | 设置阴影纵向坐标开始位置。 |
android:shadowRadius | 设置阴影的半径。设置为0.1就变成字体的颜色了, 一般设置为3.0的效果比较好。 |
android:text | 设置显示文本. |
android:textAppearance | 设置文字外观。如?android:attr/textAppearanceLargeInverse这里引用的是系统自带的一个外观, ?表示系统是否有这种外观,否则使用默认的外观。可设置的值如下: textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse /textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/ textAppearanceSmallInverse |
android:textColor | 设置文本颜色 |
android:textColorHighlight | 被选中文字的底色,默认为蓝色 |
android:textColorHint | 设置提示信息文字的颜色,默认为灰色。与hint一起使用。 |
android:textColorLink | 文字链接的颜色. |
android:textScaleX | 设置文字缩放,默认为1.0f。 |
android:textSize | 设置文字大小,推荐度量单位sp,如 15sp |
android:textStyle | 设置字形bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2,`可以设置一个或多个,用“|”隔开 |
android:typeface | 设置文本字体,必须是以下常量值之一:normal0, sans1, serif2, monospace(等宽字体) 3 |
android:height | 设置文本区域的高度,支持度量单位:px(像素), dp, sp, in, mm(毫米) |
android:maxHeight | 设置文本区域的最大高度 |
android:minHeight | 设置文本区域的最小高度 |
android:width | 设置文本区域的宽度,支持度量单位:px(像素), dp, sp, in, mm(毫米)。 |
android:maxWidth | 设置文本区域的最大宽度 |
android:minWidth | 设置文本区域的最小宽度 |
出处
/article/4602562.html相关文章推荐
- 可变参数宏...和__VA_ARGS__
- Cocos2d-JS 创建node节点示例
- 基于1.3.3版本tooltip的datagrid单元格tip实现
- 通知客户端不要缓存
- 关于C++引用的一些注意点
- 一次压力测试经历
- Centos启动默认打开网络
- C#------事物的回滚
- 前台html的样式调试
- Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)
- 不懂得理解别人
- hadoop 2.7.1源码导入eclipse
- 下载
- 每日python(6)
- hiho#1145 : 幻想乡的日常
- CSS选择符及优先级计算
- byte[]和InputStream的相互转换
- 三部曲
- Lowmemorykiller笔记
- C# DataTable的詳細用法 (转)