Android基本控件的使用(一)

本章将介绍一下内容,均为XML设置UI:

  • 文本框
  • 编辑框
  • 普通按钮&图片按钮
  • 单选按钮
  • 复选框

文本框TextView

支持的XML属性

属性 作用
android:autoLinkl 将文本以指定的格式转变 none、web、email、phone、map、all
android:gravity 设置文本框内的的文本对齐方式,多个属性值用竖线隔开 top、bottom、left、right、center_vertical、fill_vertical、center_horizon、fill_horizon、center、fill、clip_vertical、clip_horizon
android:hint 当文本框无值时设置默认显示文本
android:inputType 指定文本框显示文本的内容 textPassword、textEmailAddress、phone、data
android:singleLine 文本是否单行显示 true、false
android:text 显示文本
android:textColor 文本显示颜色 #rgb、#argb、#rrggbb、#aarrggbb
android:textSize 文本大小 dp、px、pt、sp、in
android:width 文本框的宽 dp、px、pt、sp、in
android:height 文本框的长度 dp、px、pt、sp、in
android:drawableTop 文本框中图片在文本的上边 @drawable/XXX
android:drawableBottom 文本框中图片在文本的下边 @drawable/XXX
android:drawableLeft 文本框中图片在文本的左边 @drawable/XXX
android:drawableRight 文本框中图片在文本的右边 @drawable/XXX
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="123456789"
        android:autoLink="phone"
         />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="123456789@qq.com"
        android:autoLink="email"
         />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="www.baidu.com"
        android:autoLink="web"
         />
    <!--autoLink中的格式要与text中的内容相照应-->
	 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="www.baidu.com"
        android:autoLink="phone"
         />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="显示文本信息" 
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="无内容时显示的信息" 
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="单行显示1234567890111111111111111111111111111" 
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="无单行显示属性1234567890111111111111111111111111111" 
        />
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="颜色"
        android:textColor="#0ff"
        />
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="大小"
        android:textSize="55sp"
        />
         <!--字体大小不会变,但标签所占的面积发生了变化-->
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:width="88dp"
        />
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:height="105dp"
        />
	<TextView
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="权重右"
        android:gravity="right"
        />
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="带图片且图片在上"
        android:drawableTop="@drawable/ic_launcher"
        />
        <!--密码类型-->
	<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="123456789"
        android:inputType="textPassword"
        />
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值