Android 中一些常用的 UI 控件有:

TextView(文本框)、
EditView(输入框)、
Button(按钮)、
RadioButton(单选按钮)、
ImageView(图像视图)、
ToggleButton(开关按钮) 等等

1、TextView(文本框)

TextView 中的一些属性说明:

layout 布局代码如下:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/TextView1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="这是 TextView(文本框)"android:textColor="#FF0000"android:textStyle="bold|italic"android:textSize="30sp"android:layout_gravity="center"android:background="#00FF00"/></LinearLayout>

页面效果如下:

  • 另若想要文本框和字体都居中效果时
    layout 布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:background="#00FFFF"><TextViewandroid:id="@+id/TextView1"android:layout_width="200dp"android:layout_height="200dp"android:text="这是 TextView(文本框)"android:textColor="#FF0000"android:textStyle="bold|italic"android:textSize="19sp"android:gravity="center"android:background="#00FF00"/></LinearLayout>

页面效果如下:

①带阴影的 TextView 属性

②带边框的 TextView

shapeDrawable 资源文件的几个节点以及属性说明:

③带图片(drawableXxx)的 TextView

基本用法:
设置图片的核心其实就是: drawableXxx; 可以设置四个方向的图片:

drawableTop(上),
drawableButtom(下),
drawableLeft(左),
drawableRight(右)

另外,也可以使用 drawablePadding 来设置图片与文字间的间距!

④使用 autoLink 属性识别链接类型

当文字中出现了 URL,E-Mail,电话号码,地图的时候,我们可以通过设置 autoLink 属性;当我们点击 文字中对应部分的文字,即可跳转至某默认 APP,比如一串号码,点击后跳转至拨号界面等等!

⑤ TextView 使用 HTML:

常用的标签:

2、EditText(输入框)

和 TextView(文本框)非常类似,最大的区别是:EditText 可以接受用户编辑输入!EditText 继承 TextView, 可以进行编辑操作,将用户信息传递给 Android 程序。还可以为 EditText 控件设置监听器,用来测试用户输入的内容是否合法等等。

hint 设置默认提示文本,编辑输入文本内容后,提示内容消失
获得焦点后全选组件内所有文本内容
限制输入类型
设置最小行,最多行,单行,多行,自动换行…

layout 布局代码如下:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="30dp"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="账号:"android:textSize="50sp"android:textColor="#FF0000"/><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="请输入账号"android:textSize="30sp"android:maxLines="2"/></LinearLayout>

页面效果如下:

3、Button 与 ImageButton(图像按钮):

StateListDrawable 是 Drawable 资源的一种,可以根据不同的状态,设置不同的图片效果,关键节点 < selector >,我们只需要将 Button 的 background 属性设置为该 drawable 资源即可轻松实现,按下按钮时不同的按钮颜色或背景!

设置的属性:

4、ImageView(图像视图):

scaleType 设置缩放类型值:

  • 布局中指定图片 android:src="@drawable/image_1"

5、RadioButton(单选按钮) & Checkbox(复选框):

RadioButton 方法获取相关信息;

RadioGroup 是单选组合框,由多个单选按钮RadioButton 组成,实现单选状态。RadioButton(单选按钮) 需要与 RadioGroup 配合使用,提供两个或多个互斥选项集。

layout 布局代码如下:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"><LinearLayoutandroid:id="@+id/gender_line"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginRight="15dp"android:layout_marginLeft="15dp"android:layout_marginTop="10dp"android:layout_marginBottom="10dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="性         别:"android:textSize="14sp"></TextView><RadioGroupandroid:id="@+id/gender"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"android:textSize="14sp"android:layout_marginLeft="30dp"android:layout_marginRight="20dp"></RadioButton><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"android:textSize="14sp"android:layout_marginLeft="30dp"android:layout_marginRight="20dp"></RadioButton></RadioGroup></LinearLayout><LinearLayoutandroid:id="@+id/likes_line"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginRight="15dp"android:layout_marginLeft="15dp"android:layout_marginTop="10dp"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="喜         好:"android:textSize="14sp"></TextView><CheckBoxandroid:id="@+id/play_game"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="敲代码"android:textSize="14sp"android:layout_marginLeft="30dp"android:layout_marginRight="20dp"android:checked="true"></CheckBox><CheckBoxandroid:id="@+id/play_balls"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="打球"android:textSize="14sp"android:layout_marginLeft="10dp"android:layout_marginRight="20dp"></CheckBox><CheckBoxandroid:id="@+id/play_man"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="打人"android:textSize="14sp"android:layout_marginLeft="10dp"></CheckBox></LinearLayout>
</LinearLayout>

页面效果如下:

6、ToggleButton(开关按钮) & Switch(开关):

①开关按钮相关属性:

②开关相关属性:


Note:
欢迎点赞,留言,转载请在文章页面明显位置给出原文链接
知者,感谢您在茫茫人海中阅读了我的文章
没有个性 哪来的签名!
详情请关注点我
持续更新中

扫一扫 有惊喜!

© 2021 05 - Guyu.com | 【版权所有 侵权必究】

Android 常用的控件总结相关推荐

  1. android控件常用的属性,android?常用的控件属性

    1.Android RelativeLayout 属性 // 相对于给定ID控件 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_bel ...

  2. Android开发 入门篇(二) - 常用UI控件

    文章目录 控件 Button TextView EditText ImageView ProgressBar AlertDialog ProgressDialog 布局 LenearLayout an ...

  3. 004 Android之其他控件

    文章目录 ListView ListView常用属性 ListView基本使用 ListView动态插入数据 ListView实现图文混排 Adapter Adapter(适配器种类) 自定义Adap ...

  4. 安卓入门系列-07常用UI控件(长文)

    常用UI控件 简介 这一篇介绍开发中的常用UI控件. 布局管理器 所有布局管理器都是ViewGroup的子类,都可作为容器类使用.继承自View,所以也可嵌套. 常见的布局之前已经提到了三种,这里不再 ...

  5. android让一个控件跟上面控件对其,学个明白--Android控件架构

    Android控件架构 1.什么是View? View是Android中所有控件的基类.View是界面层的控件的一种抽象,它代表了一个控件.在Android中每个控件都会在界面中占得一块矩形的区域.在 ...

  6. android md 控件,Android基本UI控件.md

    # Android基本UI控件 ## *TextView 文本框* ### TextView常用用法 | 主要方法 | 功能描述 | | :----------: | :--------------- ...

  7. android按钮控件常见问题,Android的基本控件和Activity的应用总结

    Android的基本控件 常用界面控件 TextView 显示文本信息 button 普通按钮 EditText 可编辑的文本框组件(输入框) ImageView 用于显示图片 ImageBUtton ...

  8. android 自定义view控件,Android 自定义View——自定义View控件

    Android给我们提供了大量的View控件,但这还是远远满足不了我们的要求,有时候开发所需要的控件形式是在Android提供的控件中是不存在,这就需要我们自己去定义一个.那么如何自定义控件? 学习自 ...

  9. android 柱状图_安卓控件 仪表盘控件 柱状图控件 曲线控件 xamarin.android 分类器 瓶子控件 报警控件 水箱控件 进度条控件等...

    本篇博客主要介绍一个控件库,HslControls.dll 的界面,这个控件库支持winform,winform的参考另一篇文章:https://www.cnblogs.com/dathlin/p/1 ...

  10. android预览ppt插件,Android UI基本控件.ppt

    Android UI基本控件 Android 开发 常用基本控件 常用控件(Widget) 文本控件 TextView EditText 按钮控件 Button ImageButton 状态开关按钮 ...

最新文章

  1. 从零开始学 Python 之运算符
  2. 关于gradle加快构建速度采用阿里云中央仓库的配置
  3. L1-069 胎压监测 (15 分)
  4. MySQL 字段内容区分大小写
  5. 动态网站的技术路线_派康大会官方网站建设项目开通上线啦!
  6. apache2.4.7 make报错[exports.lo] Error 1 解决方法
  7. 【解决方案】K2 BPM_赋能房地产业务高效运营_全球领先的工作流引擎
  8. Java并发编程之线程安全性
  9. sql 服务器时间修改时间,教您如何修改sql server时间
  10. 品优影视建站系统1.3.6.5开源绿色版
  11. Windows XP SP3安装后瘦身法
  12. 电子身份证助力打击钓鱼攻击
  13. 计算机主机中包,百度地图脱机包最终可以在计算机上导入
  14. 前端入门学习阶段(3)
  15. cartographer_pose_extrapolator
  16. CVPR2019| 百度17篇CVPR论文学习记录(包含:无人驾驶、神经网络、GAN、无监督学习、目标检测)
  17. 安卓美化——添加下拉菜单图片或下拉菜单透明
  18. MouseManager
  19. 研究表明:菜鸟爱用右脑,专家爱用左脑!
  20. 东北大学计算机2020年多少分,2020年东北大学录取分数线公布

热门文章

  1. 新版win10的恢复语言栏设置
  2. DEDE源码分析与学习之三: member/archives_*.php文件解读
  3. 校园网连不上,火绒检测dns错误但修复不了,360直接搞定,nice!
  4. Like My Mother Always Said… by Erin McHugh
  5. matlab中marker太密,markersize_想问下MATLAB里 ‘Markersize’ 设置的值是‘Marker_
  6. 沟通表达的实用技巧和练习方法
  7. 三种T检验的详细区分
  8. python读取tiff图像,浅谈python下tiff图像的读取和保存方法
  9. leetcode--728.自除数
  10. 【原创】EXCEL数组公式(1)----数组公式和普通公式计算具体比较