文本款(TextView)和编辑框(EditText)的功能和用法

TextView直接继承了View,他还是EditText、Button两个UI组件的父类,TextView的作用就是在界面上显示文字(相当于Java中AWT中标签[JLabel],但有比他强大些)。

TextView类及其子类的类图如图所示:

TextView的XML属性及相关方法和说明:

XML属性

相关方法

说明

android:autoLink

setAutoLinkMask(int)

是否符合指定格式的文本转换为可单击的超链接形式

android:cursorVisible

setCursorVisible(boolean)

设置该文本框的光标是否可见

android:drawableBottom

setCompounDrawablesWithIntrinsicBounds

(Drawable,Drawable,Drawable,Drawable)

在文本框内文本的底端绘制指定图像

android:drawableLeft

setCompounDrawablesWithIntrinsicBounds

(Drawable,Drawable,Drawable,Drawable)

在文本框内文本的左边绘制指定图像

android:drawablePadding

setCompounDrawablesWithIntrinsicBounds

(Drawable,Drawable,Drawable,Drawable)

设置文本框内文本与图形之间的间距

android:drawableRight

setCompounDrawablesWithIntrinsicBounds

(Drawable,Drawable,Drawable,Drawable)

在文本框内文本的右边绘制指定图像

android:drawableTop

setCompounDrawablesWithIntrinsicBounds

(Drawable,Drawable,Drawable,Drawable)

在文本框内文本的顶端绘制指定图像

android:editable

设置该文本是否允许编辑

android:ellipsize

设置当显示的文本超过TextView的长度是如何处理文本内容

android:gracity

setGravity(int)

设置文本框内文本的对齐方式

android:height

setHeight(int)

设置该文本框的高度(以pixel为单位)

android:hint

setHint(int)

设置当该文本框内容为空时,文本框内默认显示的提示文本

android:minHeight

setMinHeight(int)

设置该文本框的最小高度(以pixel为单位)

android:maxHeight

setMaxHeight(int)

设置该文本框的最大高度(以pixel为单位)

android:minWidth

setMinWidth(int)

设置该文本框的最小宽度(以pixel为单位)

android:maxWidth

setMaxWidth(int)

设置该文本框的最大宽度(以pixel为单位)

android:lines

setLines(int)

设置该文本框默认占几行

android:MiLines

setMiLines(int)

设置该文本框最少占几行

android:MaxLines

setMaxLines(int)

设置该文本框最多占几行

android:password

setTransformationMethod(TransfirmationMethod)

设置该文本框是一个密码框(以点代替字符)

android:phoneNumber

setKevListener(KeyListener)

设置该文本框只能接受电话号码

android:scrollHorizontally

setHorizontallyScorlling(boolean)

设置当该文本框不够显示全部内容时是否允许水平滚动

android:selectAllOnFocus

setSelectAllOnFocus(boolean)

如果文本框的内容可选择,设置当它获得焦点时是否自动选中所有文本

android:singleLine

setTransformationMethod

设置该文本框是否为单行模式。如果设为true,文本框不会换行

android:shadowColor

setShadowLayer(float,float,float,int)

设置文本框内文本的阴影的颜色

android:shadowDx

setShadowLayer(float,float,float,int)

设置文本框内文本的阴影在水平方向的偏移

android:shadowDy

setShadowLayer(float,float,float,int)

设置文本框内文本的阴影在垂直方向的偏移

android:shadowRadius

setShadowLayer(float,float,float,int)

设置文本框内文本的阴影的角度

android:text

setText(CharSequence)

设置文本框内文本的内容

android:textColor

setTextColor(ColorStateList)

设置该文本框内文本的颜色

android:tetColorHighlight

setHighlightColor(int)

设置该文本框内文本被选中时的颜色

android:textScaleX

setTextScaleX(float)

设置该文本框内文本水平方向上的缩放因子

android:textSize

setTextSize(float)

设置该文本框内文本的字体大小

android:textStyle

setTypeface(Typeface)

设置该文本框内文本的字体风格,如粗体,斜体

android:typeface

setTypeface(Typeface)

设置该文本框内文本的字体

android:width

setWidth(int)

设置该文本框的宽度

上表中android:autoLink属性值是如下几个属性值的一个或几个,多个属性值之间用竖线隔开:

none:不设置任何超链接

web(对应于Linkify.WEB_URLS):将文本中的URL地址转换为超链接

email(对应于Linkify.EMAIL_ADDRESSES):将文本中的E-mail地址转换为超链接

phone(对应于Linkify.PHONE_NUMBERS):将文本中的电话号码转换为超练接

map(对应于Linkify.MAP_ADDRESSES):将文本中的接到地址转换为超链接

all:相当于指定weblemaillphonelmap

上表中android:ellipsize属性可支持如下几个属性值。

none:不进行任何处理

start:在文本开头部分进行省略

middle:在文本中间部分进行省略

end:在文本结尾出进行省略

marquee:在文本结尾出以淡出的方式省略

下面我们用例子来例举上表中的一些属性:不同字体、不同颜色的文本、URL

layout/main.xml

1

2 xmlns:tools="http://schemas.android.com/tools"

3 android:orientation="vertical"

4 android:layout_width="fill_parent"

5 android:layout_height="fill_parent">

6

7

8

10 android:layout_height="wrap_content"

11 android:text="我爱Java"

12 android:textSize="20pt"

13 />

14

15

17 android:layout_height="wrap_content"

18 android:singleLine="true"

19 android:text="我爱Java我爱Java我爱Java我爱Java我爱Java我aaaJava"

20 android:ellipsize="middle"

21 />

22

23

25 android:layout_height="wrap_content"

26 android:singleLine="true"

27 android:text28 android:autoLink="email"

29 />

30

31

33 android:layout_height="wrap_content"

34 android:text="测试文字"

35 android:shadowColor="#0000ff"

36 android:shadowDx="15.0"

37 android:shadowDy="20.0"

38 android:shadowRadius="45.0"

39 android:textColor="#ff0000"

40 android:textSize="25pt"

41 />

42

43

44 android:layout_width="fill_parent"

45 android:layout_height="wrap_content"

46 android:text="@string/hello"

47 android:password="true"

48 />

49

50

所展现的效果图如下:

范例:带边框、图片的TextView

1

2 xmlns:tools="http://schemas.android.com/tools"

3 android:orientation="vertical"

4 android:layout_width="fill_parent"

5 android:layout_height="fill_parent">

6

7

8

10 android:layout_height="wrap_content"

11 android:text="带边框的文本"

12 android:background="@drawable/bg_border"

13 android:textColor="@color/abc_search_url_text_holo"

14 />

15

16

17

19 android:layout_height="wrap_content"

20 android:text="带图片的文本"

21 android:drawableLeft="@drawable/ic_launcher"

22 />

23

24

效果图:

范例:一个注册界面

1

2 xmlns:tools="http://schemas.android.com/tools"

3 android:orientation="vertical"

4 android:layout_width="fill_parent"

5 android:layout_height="fill_parent">

6

7

9 android:layout_height="wrap_content"

10 android:text="用户名:"

11 android:textSize="10sp"

12 android:background="@drawable/bg_border"

13 />

14

16 android:layout_height="wrap_content"

17 android:hint="请填写登录帐号"

18 android:selectAllOnFocus="true"

19 />

20

21

22

24 android:layout_height="wrap_content"

25 android:text="密码:"

26 android:textSize="10pt"

27 android:background="@drawable/bg_border"

28 />

29

31 android:layout_height="wrap_content"

32 android:password="true"

33 />

34

35

36

38 android:layout_height="wrap_content"

39 android:text="电话号码:"

40 android:textSize="10pt"

41 android:background="@drawable/bg_border"

42 />

43

45 android:layout_height="wrap_content"

46 android:hint="请填写您的电话号码"

47 android:selectAllOnFocus="true"

48 android:phoneNumber="true"

49 />

50

51

53 android:layout_height="wrap_content"

54 android:text="注册"

55 />

56

57

58

上面代码里面的TextView是设置了背景图片的,所以在展示的效果图上你们呢会看到三个黑的框框,为什么三个框框的会有一个比另外两个小,那是因为我设置的宽度单位不一样(用户名的宽度是sp,其他的是用的pt);所展示的效果,效果图如下:

原文:http://www.cnblogs.com/Yang-jing/p/3747469.html

android用来显示界面的组件,Android 自学之基本界面组件(上)相关推荐

  1. android 锁屏显示音乐播放器,Android锁屏界面控制音乐播放

    目前,在锁屏界面控制音乐播放有两种常用方式. 第一种方式:原生Android系统及自带音乐播放器. 锁屏界面端: 原生Android中,锁屏界面相关的UI由KeyguardHostView提供,Key ...

  2. android 首页广告显示不出来的,android – Admob插页式广告(全屏)不会显示

    您没有为interstitialAd调用loadAd().广告插播广告应在您展示广告之前加载. interstitialAd.loadAd(adRequest); 你也应该在调用show()之前检查它 ...

  3. android显示二维毫秒,Android 悬浮窗显示毫秒级时间

    Android 悬浮窗显示毫秒级时间Android 悬浮窗显示毫秒级时间. 运行效果如下: 1.新建工程"FloatWindowDemo2", 工程如下: 2. "Mai ...

  4. Android TextView 竖向显示(字体长度对字体位置有影响)

    需求: Android字体竖向显示 1.使用android:rotation="90":不足:如果字体很长,那么会有很长的距离. 2.自定义TextView竖向布局.消除了字体长度 ...

  5. Android 仿微信显示的聊天照片

    Android 仿微信显示的聊天照片 Android 仿微信显示的聊天照片,效果如下图所示: 这种显示的样式就是和微信的显示照片的样式是一样的,微信的实现我不知道是否和我一样,今天我来和大家介绍一下我 ...

  6. android显示二维毫秒,Android应用开发Android 悬浮窗显示毫秒级时间

    本文将带你了解Android应用开发Android 悬浮窗显示毫秒级时间,希望本文对大家学Android有所帮助. Android   悬浮窗显示毫秒级时间Android 悬浮窗显示毫秒级时间. 运行 ...

  7. android图片显示组件,Android可循环显示图像的Android Gallery组件用法实例

    本文实例分析了Android可循环显示图像的Android Gallery组件用法.分享给大家供大家参考,具体如下: Gallery组件主要用于横向显示图像列表,不过按常规做法.Gallery组件只能 ...

  8. Android 复杂Listview的显示,仿金山手机助手程序卸载界面

    仿金山手机助手程序卸载界面,主要使用的知识点有: 1.listview中添加textview.listview排列显示 2.PopupWindow的使用 3.程序卸载 4.帧布局的使用 下面是项目中A ...

  9. 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面

    转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/8987342  这篇文章算是对整个引导界面开发专题的一个终结了吧,个人觉得大部 ...

最新文章

  1. 响应因特网端口ping命令_如何使用Ping命令识别基本的Internet问题
  2. Combotree--别样的构建层级json字符串
  3. 关于Unity中的Mesh Collider碰撞器
  4. jQuery Ajax - ajax()方法,参数注释
  5. 【深入浅出etcd系列】1. 架构概览
  6. 红橙Darren视频笔记 动画讲解 仿58同城 加载动画
  7. eclipse调试第一个java程序
  8. 操作系统—死锁的概念
  9. vs 生成get set_使用EasyCode+Lombok快速生成增删查改的代码
  10. js实现键盘按键映射
  11. 8路USB继电器模块 windows Linux使用
  12. 双因素方差分析 matlab,MATLAB的双因素有交互效应的方差分析
  13. 11x 程序员专属 TapTap 代码编辑器主题
  14. KGB知识图谱的功能和特色介绍
  15. 快速学习-mocha 简介与入门
  16. Open3d读写ply点云文件
  17. vue 过滤器做字数限制并显示省略号
  18. 企业微信报错,提示无权限访问
  19. 行测测评(二)——图形找规律技巧
  20. ROS中的imu_transformer包是什么,在哪里可以下载啊

热门文章

  1. shell如何检测linux发行版本,shell判断软件版本
  2. 实战| JSP Servlet Mysql学生信息管理系统
  3. 基于JAVA+Spring+MYSQL的房屋出售系统
  4. face alignment---各种算法框架
  5. webstorm编辑器相关
  6. 用户空间和内核空间通讯之【Netlink 中】
  7. 多线程调用生成主键流水号存储过程产生主键冲突问题解决方案
  8. asp.net 小记
  9. 向日葵linux 用电脑远程控制与管理,远程控制软件向日葵和teamviewer的区别和使用...
  10. docker删除所有镜像_Docker 常用命令