Android简单控件的使用

这篇博客介绍了Android中常见的UI控件的使用,包括TextView的textcolor属性设置,Button的点击事件设定,EditText的常用属性及获取信息方法,以及ImageView的属性应用,并给出了具体示例。
摘要由CSDN通过智能技术生成

TextView

TextView控件用于显示文本信息

TextView常用属性

属性名称 功能描述
android:layout_width 设置控件的宽度
android:layout_height 设置控件的高度
android:id 设置控件的唯一标识
android:background 设置控件的背景
android:layout_margin 设置控件与屏幕边界或周围控件、布局的距离
android:padding 设置控件与该控件中内容的距离
android:text 设置控件的文本内容
android:textColor 设置控件的颜色
android:textSize 设置控件的大小
android:gravity 设置文本内容的位置
android:maxLength 设置文本最大长度,超出此长度的文本不显示
android:lines 设置文本的行数,超出此长度的文本不显示
android:maxLines 设置文本的最大行数,超出此行数的文本不显示
android:ellipsize 设置当文本超出TextView规定的范围显示方式,属性值可选为“start”、“middle”和“end”,分别表示当文本超出控件规定范围时,在文本开始、中间或者末尾显示省略号
android:drawableTop 在文本顶部显示图像
android:lineSpacingExtra 设置文本的行间距
android:textStyle 设置文本样式,如bold(粗体),italic(斜体),normal(正常)

设置文本颜色的三种方法

textcolor属性可以设置:

  1. 颜色码
  2. @android定义的颜色值,由谷歌公司提供选择
  3. colors.xml自己定义的颜色值

@android定义的颜色值:在这里插入图片描述
colors.xml自己定义的颜色值:
在这里插入图片描述
在这里插入图片描述
直接使用颜色码:
在这里插入图片描述

举例

    <TextView
        android:text="测试文本"
        android:textSize="30dp"
        android:background="#ABBB86FC"
        android:textColor="@color/black"
        android:textStyle="italic|bold"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </TextView>

在这里插入图片描述

Button

button控件表示按钮,它继承自TextView控件。

为button控件设置点击事件的三种方式

  1. 在布局文件中指定onClick属性的方式设置点击事件
<!--布局文件-->
<Button
    android:id="@+id/bt2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick=
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值