你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

Android TextView的属性与应用,一文搞懂JVM架构

2021/12/28 12:26:06

设置文本的额外的输入数据。

android:ellipsize


设置当文字过长时,该控件该如何显示。有如下值设置:”start”—?省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间; ”marquee” ——以跑马灯的方式显示(动画横向移动)

android:freezesText


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

android:gravity


设置文本位置,如设置成“center”,文本将居中显示。

android:hintText


为空时显示的文字提示信息,可通过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


设置文本的类型,用于帮助输入法显示合适的键盘类型。在EditView中再详细说明,这里无效果。

android:linksClickable


设置链接是否点击连接,即使设置了autoLink。

android:marqueeRepeatLimit


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

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


设置输入法选项,此处无用,在EditText将进一步讨论。

android:scrollHorizontally


设置文本超出TextView的宽度的情况下,是否出现横拉条。

android:selectAllOnFocus


如果文本是可选择的,让他获取焦点而不是将光标移动为文本的开始位置或者末尾位置。TextView中设置后无效果。

android:shadowColor


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

android:shadowDx


设置阴影横向坐标开始位置。

android:shadowDy


设置阴影纵向坐标开始位置。

android:shadowRadius


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

android:singleLine


设置单行显示。如果和layout_width一起使用,当文本不能全部显示时,后面用“…”来表示。如android:text=”test_ singleLine ”

android:singleLine=”true”


将只显示“t…”。如果不设置singleLine或者设置为false,文本将自动换行

android:text


设置显示文本.

android:textAppearance


设置文字外观。如“?android:attr/textAppearanceLargeInverse”这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。可设置的值如下:

  • textAppearanceButton
  • textAppearanceInverse
  • textAppearanceLargeInverse
  • 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


设置文本字体,必须是以下常量值之一:normal 0, sans 1, serif 2, monospace(等宽字体) 3]

android:height


设置文本区域的高度,支持度量单位:px(像素)/dp/sp/in/mm(毫米)

android:maxHeight


设置文本区域的最大高度

android:minHeight


设置文本区域的最小高度

android:width


设置文本区域的宽度,支持度量单位:px(像素)/dp/sp/in/mm(毫米),与layout_width的区别看这里。

android:maxWidth


设置文本区域的最大宽度

android:minWidth


设置文本区域的最小宽度

TextView的圆角:


![这里写图片描述](https://img-blog.csdn.net/2015022711015748

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整资料开源分享

<?xml version="1.0" encoding="utf-8"?>

<stroke android:width=“0.5dp”

android:color="@android:color/black" />

<padding

android:top=“10dp”

android:bottom=“10dp”

android:left=“10dp”

android:right=“10dp” />

<gradient

android:angle=“270”

android:startColor="#00FFFF"

android:endColor="#13C7AF" />

光标颜色


修改光标颜色,很容易实现,只需在对应的EditText修改textCursorDrawable属性即可:

<EditText

android:id="@+id/etCheck"

android:hint=“验证码”

android:textColor="#0000ff"

android:textCursorDrawable="@null"

android:inputType=“number”

最后

下面是辛苦给大家整理的学习路线

<padding

android:top=“10dp”

android:bottom=“10dp”

android:left=“10dp”

android:right=“10dp” />

<gradient

android:angle=“270”

android:startColor="#00FFFF"

android:endColor="#13C7AF" />

光标颜色


修改光标颜色,很容易实现,只需在对应的EditText修改textCursorDrawable属性即可:

<EditText

android:id="@+id/etCheck"

android:hint=“验证码”

android:textColor="#0000ff"

android:textCursorDrawable="@null"

android:inputType=“number”

最后

下面是辛苦给大家整理的学习路线

[外链图片转存中…(img-xfSRD1t2-1640665359523)]

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录