Android基本组件TextView和EditView

本文详细介绍了Android开发中常用的TextView和EditText控件的属性及使用方法。包括如何设置文本颜色、大小、对齐方式,以及如何实现单行或多行文本输入等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.TextView

用于在屏幕上显示文本,可以显示单行文本,多行文本,和带图像的文本。

常用xml属性

(1)android:autoLink,用于指定是否将指定的文本转换为可单机的超链接形式,其属性值有none,web,email,phone,map和all

(2)android:drawableBottom;android:drawableLeft;android:drawableRight;android:drawableTop   分别表示文本框在在各个位置的指定图像

(3)android:gravity  用于设置文本框内文本的对齐方式 ,其属性值可以组合,用“|”隔开

(4)android:hint  用于设置当文本框中内容为空的时候,默认的显示的提示文字

(5)android:inputType  用于指定文本的显示类型,其可选值有 textPassword,textEmailAddress,phone,date等,可以同时指定多个,用“|”隔开。

(6)android:singleLine 用于指定文本框是否为单行模式。其属性值是true或者false。默认的是false

(7)android:text  要显示文本的内容

(8)android:textColor  要显示文本的颜色,其属性值可以是#rgb,#argb,#rrggbb,#aarrggbb格式指定的颜色值。

(9)android:textSize  用于设置文本框类字体的大小,其属性值由数值和单位组成,其单位可以是px,pt,sp,in,pd。

(9)android:width;android:height;用于指定文本的宽度高度,已像素为单位。

TextView的使用实例

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/email"
        android:autoLink="email" 
        android:gravity="center"
        android:height="40px"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/ic_launcher"
        android:text="@string/imageTextView" />
    <TextView
        android:id="@+id/textView3"
        android:textSize="20px"
        android:textColor="#0f0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text" />
    <TextView
        android:id="@+id/textView4"
        android:textSize="20px"
        android:textColor="#f00"
        android:singleLine="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:inputType="textUri"
        android:layout_height="wrap_content"
        android:text="www.baidu.com" />

  效果如下

2 EditText

EditText是TextView的子类,所以TextView的Xml属性,EditText都有,其中android:inputType属性可以帮助输入框显示合适的类型。

<requestFocus />会获得焦点,意思就是如果你给某个edittext设置了<requestFocus />标记,并且这个edittext前面没有设置<requestFocus />标记的控件 那么这个edittext就会获得焦点,也就是输入的那个光标。

转载于:https://www.cnblogs.com/deng-c-q/p/5170394.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值