Android控件——TextView、EditText、ImageView、Button、ImageButton

这篇博客详细介绍了Android中常见的UI控件,包括TextView的wrap_content和match_parent属性,EditText的hint和inputType设置,ImageView的src和background用法,Button的text特性和明显的点击反馈,以及ImageButton结合图片和点击事件的特性。

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

  1. TextView——显示文本框控件

    TextView控件的常用属性

    • android:id——控件的id
    • android:layout_width——控件的宽度
    • android:layout_hight——控件的高度
    • android:text——文本内容
    • android:textSize——文本大小
    • android:textColor—文本颜色
    • android:backgound——控件背景

    wrap_content:包裹实际文本内容
    match_parent:当前控件铺满父类容器:2.3api之后添加的一个属性值
    fill_parent:当前控件铺满父类容器:在2.3api之前的一个属性值

2.EditText——输入文本框

  TextView控件的常用属性
  • android:id——控件的id
  • android:layout_width——控件的宽度
  • android:layout_hight——控件的高度
  • android:text——文本内容
  • android:textSize——文本大小
  • android:textColor—文本颜色
  • android:backgound——控件背景
  • android:hint——提示输入文本
  • android:inputType—文本类型

3.ImageView——显示图片的控件

ImageView属性
  • android:src=”@drawable/ic_launcher”——ImageView的图片内容
  • android:background=”@drawable/ic_launcher”——ImageView背景图片
  • android:background=”#00ff00”——ImageView的RGB颜色

4.Button——按钮

<Button
 android:id="@+id/button1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text="Button" 
/>

特征:

  • 可以作为一个按钮产生明显的点击事件
  • Button有text属性,无src属性,text当中的字符串一般是存放在value当中的string资源
  • 产生明显的点击效果
  • 和smallButton一样,只不过smallButton多一条style属性, style=”?android:attr/buttonStyleSmall”,它调用了系统下面的一个风格

5.ImageButton——图片按钮

<ImageButton
 android:id="@+id/imagebutton1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:src="@drawablebc_ab_share_pack_holo_light" 
/>

特征:

  • 可以作为一个按钮产生明显的点击事件
  • ImageButton有src属性,无text属性,不可以设置文本内容,background以及src添加一个image,当前图片上可以做一个有文本内容的图片
  • 产生明显的点击效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值