`
hulianwang2014
  • 浏览: 690039 次
文章分类
社区版块
存档分类
最新评论
  • bcworld: 排版成这样,一点看的欲望都没有了
    jfinal

Android控件之Textview

 
阅读更多

2014/04/04 决定重新系统地学习一遍Android上的各种控件

从TextView开始:

一、TextView概述

android.widget.TextView直接继承于android.view.View类.

直接子类有:Button、CheckedTextView、Chronometer、DigitalClock、EditText.

构造函数:(1)TextView(Context context)

(2)TextView(Context context,AttributeSet attrs)

(3)TextView(Context context,AttributeSet attrs,int defStyle)

TextView用于向用户显示文本,它的直接子类EditText可用于编辑文本


二、XML属性

属性
具体描述
android:autoLink
控制如URL及Email地址能否被自动发现及转换为可点击的链接
android:autoText
控制一些简单的拼写错误能否被识别
android:cursorVisible
设置编辑光标是否可见
android:enabled
指定该TextView是否可用
android:gravity
指定当该TextView中的文字小于TextView可容纳的范围时,文字显示在何处
android:height
通过像素来指定该TextView的高度
android:lines
通过行数来指定该TextView的高度
android:linksClickable
若设为false,及时autoLink找到了链接地址,也不能点击
android:maxHeight
通过像素指定控件的最大高度
android:maxLength
通过字数来指定文字最大长度
android:maxLines
通过行数来指定控件最大高度
android:maxWidth
通过像素来指定控件最大宽度
android:minHeight
与android:maxHeight相对
android:minLines
与android:maxLines相对
android:minWidth
与android:maxWidth相对
android:password
指定文字是以密码圆点显示或者直接显示文字内容
android:scrollHorizontally
指定当文字长度超过显示宽度时,能否水平滑动
android:selectAllOnFocus
如果文字可选定,直接选定所有文字而不是通过移动光标来选定
android:shadowColor
在文字底部设置阴影颜色
android:singleLine
将控件行数约束至一行,当用户按下Enter时,获取控件焦点而不是插入新的一行
android:text
TextView显示的文字
android:textAllCaps
将文字全部以大写形式显示
android:Appearance
指定文字颜色、字体、大小及字形
android:textColor
指定文字颜色
android:textColorHighlight
指定文字高亮颜色
android:textColorHint
指定文字提示颜色
android:textColorLink
指定链接文字颜色
android:textCursorDrawable
指定出现在光标下的图片
android:textIsSelectable
表明不可编辑的文字可以被选中
android:textScaleX
设置文字的水平缩放比例
android:textSize
设置文字的大小


三、常用Public方法

返回值
方法名及参数
具体描述
void
addTextChangedListener(TextWatcher watcher)
为该控件添加一个监听器,监听事件为文字发生改变
final void
append(CharSequence text)
将指定的文字添加到TextView的显示缓冲区内,并将BufferType设置为EDITABLE
void
cancelLongPress()
取消正在进行的长按动作
void
clearComposingTest()
清空正在输入的文字
void
debug(int depth)
将该控件的相关信息打印在日志输出记录上,标签为VIEW_LOG_TAG
boolean
didTouchFocusSelect()
只有当正在进行一个触摸手势时返回true
Editable
getEditableText()
将文本作为Editable对象返回,若文本不可编辑,返回null
inputFilter[]
getFliters()
返回一个inputFliter数组
CharSequence
getText()
返回TextView正在显示的文字
int
length()
返回控件中文字的长度
void
setAllCaps(boolean allCaps)

void
setKeyListener(KeyListener input)
为控件添加一个监听器,监听事件为键盘按下。当作用于虚拟键盘时有重要而微妙的不同
void
setPadding(int left,int top,int right,int bottom)
设置内边距
void
setText(ChatSequence text)
设置TextView显示的文字

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics