android md 控件,Android基本UI控件.md
# Android基本UI控件
## *TextView 文本框*
### TextView常用用法
| 主要方法 | 功能描述 |
| :----------: | :--------------------: |
| getText | 获得TextView对象的文本 |
| setText | 设置TextView对象的文本 |
| setTextColor | 设置文本显示的颜色 |
```Java
private TextView textView;
textView = (TextView) findViewById(R.id.textView);
textView.setText("文本内容");
textView.setTextColor(Color.rgb(255,255,255)); //颜色的RGB值
textView.getText().toString();
```
### TextView标签属性
| 属性名称 | 描述 |
| :---------------: | :----------: |
| android:text | 设置显示文本 |
| android:textColor | 设置文本颜色 |
| android:textSize | 设置文本大小 |
```xml
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本内容"
android:textColor="#000"
android:textSize="20sp"
/>
```
---
## *EditText 编辑框*
### EditText常用方法
| 方法 | 功能描述 |
| :------: | :------------------------: |
| getText | 得到EditText对象的文本 |
| setText | 设置文本内容 |
| setHints | 设置文本框为空时显示的文本 |
| getHints | 获取文本框为空时显示的文本 |
```java
private EditText editText;
editText = (EditText) findViewById(R.id.editText);
String text = editText.getText().toString();
editText.setText("文本内容");
editText.setHint("设置文本框为空时显示的文本");
editText.getText();
```
### EditText标签属性
| 属性名称 | 描述 |
| :---------------: | :------------------------: |
| android:textColor | 设置文本颜色 |
| android:textSize | 设置文本大小 |
| android:hint | 设置文本框为空时显示的文本 |
| android:inputType | 限定文本框输入类型 |
```xml
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:hint="设置文本框为空时显示的文本"
android:inputType="number"
/>
```
---
## *ImageView 图片视图*
### ImageView常用方法
| 方法 | 功能描述 |
| :--------------: | :-------------------------------------------: |
| getDrawable | 返回视图的可绘制对象 |
| setImageBitmap | 设置位图为该ImageView内容 |
| setImageResource | 通过资源ID设置可绘制对象为ImageView显示的内容 |
| setAlpha | 设置透明度 |
```Java
private ImageView imageView;
private Bitmap bitmap;
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setAlpha(80); //设置透明度为80%
Drawable drawable = imageView.getDrawable(); //得到drawable对象
imageView.setImageResource(R.drawable.ic_launcher_background);
imageView.setImageBitmap(bitmap);
```
### ImageView标签属性
| 属性名称 | 描述 |
| :---------: | :-------------------------------: |
| android:src | 设置可绘制对象为ImageView显示内容 |
```xml
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher_background"
/>
```
---
## *Button 按钮*
### Button常用方法
略
### Button标签属性
| 属性 | 描述 |
| :---------------: | :----------------------: |
| android:text | 设置按钮文本内容 |
| android:hint | 设置按钮为空时显示的文本 |
| android:textColor | 设置按钮文本颜色 |
| android:textSize | 设置按钮文本大小 |
| android:enabled | 设置按钮是否打开 |
```xml
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮文本"
android:textColor="#000"
android:hint="按钮为空时显示的文本"
android:textSize="20sp"
android:enabled="true"
/>
```
---
## *CheckBox 复选框*
### CheckBox 常用方法
| 方法 | 功能描述 |
| :--------: | :--------------: |
| isChecked | 判断组件是否勾选 |
| setChecked | 设置组件状态 |
```java
private CheckBox checkBox;
checkBox = (CheckBox) findViewById(R.id.checkBox);
Boolean isChecked = checkBox.isChecked(); //判断CheckBox是否选中
checkBox.setChecked(true); //设置CheckBox为选中状态
```
### CheckBox标签属性
| 属性 | 描述 |
| :-------------: | :--------------: |
| android:checked | 设置CheckBox状态 |
```xml
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
/>
```
---
## *RadioGroup和RadioButton 单项选择按钮*
### RadioGroup常用方法
| 方法 | 功能描述 |
| :--------: | :------------------: |
| checked | 单选按钮组的勾选状态 |
| chearCheck | 清除当前选择状态 |
```java
private RadioButton rb1;
private RadioButton rb2;
private RadioButton rb3;
private RadioGroup radioGroup;
rb1 = (RadioButton) findViewById(R.id.rb1);
rb2 = (RadioButton) findViewById(R.id.rb2);
rb3 = (RadioButton) findViewById(R.id.rb3);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.check(R.id.rb1); //选中id为rb1的单选框
radioGroup.clearCheck(); //清除当前选中状态
```
### RadioGroup标签属性
略
```xml
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:id="@+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
```
---
## *ToggleButton 开关按钮*
### ToggleButton常用方法
| 方法 | 功能描述 |
| :--------: | :------------------: |
| getTextoff | 获取失效状态下的文本 |
| getTextOn | 获取有效状态下的文本 |
| setChecked | 设置开关状态 |
| setTextOff | 设置失效状态下的文本 |
| setTextOn | 设置有效状态下的文本 |
```java
private ToggleButton toggleButton;
toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
String textOff = toggleButton.getTextOff().toString(); //获取失效状态下的文本
String textOn = toggleButton.getTextOn().toString();
toggleButton.setTextOff("失效状态下的文本");
toggleButton.setTextOn("有效状态下的文本");
toggleButton.setChecked(true); //设置开关为打开状态
```
### ToggleButton标签属性
| 属性名称 | 描述 |
| :-------------: | :--------------: |
| android:textOff | 未选中时按钮文本 |
| android:textOn | 选中时按钮文本 |
| android:checked | 设置按钮状态 |
```xml
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="选中时按钮文本"
android:textOff="未选中时按钮文本"
android:checked="false"
/>
```
---
## *SeekBar 拖动条*
### SeekBar 常用方法
| 方法 | 功能描述 |
| :---------: | :------------: |
| getMax | 获取范围最大值 |
| getProgress | 获取当前进度值 |
| setMax | 设置范围最大值 |
```Java
private SeekBar seekBar;
seekBar = (SeekBar) findViewById(R.id.seekBar);
seekBar.setMax(100); //设置拖动条最大值为100
seekBar.getMax(); //得到当前拖动条的最大值
seekBar.getProgress(); //获取当前进度值
```
### SeekBar标签属性
| 属性名称 | 描述 |
| :--------------: | :------------: |
| android:max | 设置范围最大值 |
| android:progress | 设置当前进度值 |
```xml
android:id="@+id/seekBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="250"
android:progress="100"
/>
```
---
## *ProgressBar 进度条*
### ProgressBar 常用方法
| 方法 | 功能描述 |
| :---------: | :------------: |
| getMax | 获取范围最大值 |
| getProgress | 获取当前进度值 |
```java
private ProgressBar progressBar;
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.getMax();
progressBar.getProgress(); //获取当前进度
```
### ProgressBar 标签属性
| 属性名称 | 描述 |
| :--------------: | :--------------------: |
| android:max | 设置进度条最大值 |
| android:progress | 设置进度条的默认进度 |
| style | 进度条样式(详情见下表) |
| 进度条样式 | 描述 |
| :----------------------------------------------: | :--------------: |
| style="?android:attr/progressBarStyleHorizontal" | 水平长形进度条 |
| style="?android:attr/progressBarStyleLarge" | 超大号圆形进度条 |
| style="?android:attr/progressBarStyleSmall" | 标准圆形进度条 |
| style="?android:attr/progressBarStyleSmallTitle" | 标题型圆形进度条 |
```xml
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="250"
android:progress="100"
style="?android:attr/progressBarStyleHorizontal"
/>
```
---
一键复制
编辑
Web IDE
原始数据
按行查看
历史
android md 控件,Android基本UI控件.md相关推荐
- Android 自定义titlebar控件(自定义UI控件)
1.创建自定义的属性: 2.在自定义的布局中获取属性: 3.在mainActivity中使用 自定义控件,并使用自定义属性赋值. 1.创建自定义的属性创建 values/attr.xml 文件: &l ...
- android ui新控件,android_常用UI控件_01_TextView3_点击打开新的activity
点击textview打开新的activity (1) MainActivity.javapackage com.example.android_textview_opennewactivity; im ...
- android 画布裁剪,一种基于Android系统对UI控件进行轮廓剪裁及美化的方法与流程...
本发明涉及Android应用的技术领域,特别涉及一种基于Android系统对UI控件进行轮廓剪裁及美化的方法. 背景技术: 目前,随着智能电视的普及,Android应用层出不穷,而那些表现形式单一.传 ...
- 安卓开发入门教程-UI控件_EditText
什么是EditText EditText是用于进行文本输入的UI控件. 基础样例 1.普通输入 效果图 代码 <EditTextandroid:layout_width="wrap_c ...
- 【iOS 开发】基本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
博客地址 : http://blog.csdn.net/shulianghan/article/details/50051499 ; 一. UI 控件简介 1. UI 控件分类 UI 控件分类 : 活 ...
- JavaFX UI控件教程(二)之JavaFX UI控件
翻译自 JavaFX UI控件 本章概述了通过API提供的JavaFX UI控件. JavaFX UI控件是使用场景图中的节点构建的.因此,控件可以使用JavaFX平台的视觉丰富功能.由于JavaF ...
- 8月2日Cocos 斗鱼直播:2小时现撸自定义UI控件
嘟!嘟!嘟!Cocos斗鱼直播秀,将在下周二晚八点准时开车!本期我们要派出的当家主播,是位混迹江湖多年的老司机--子龙山人. 各位宝宝们先记得收好下面这张门票,下周二别忘记上车哦! 8月2日(周二)2 ...
- android基础ui控件,Android基础——基础UI控件
日历,时钟,计时器 package com.example.mybaseuii; import androidx.appcompat.app.AppCompatActivity; import and ...
- android 获取控件高度_安卓开发入门教程UI控件_ImageView
什么是ImageView ImageView是用于显示图片的UI控件. 基础样例 1.展示本地图片 效果图 代码 <ImageViewandroid:layout_width="wra ...
最新文章
- 最前沿的科学, 寻找最聪明的你—“宏基因组”公众号编辑招募
- 医学图像分割研究思路
- 开发笔记:掉落系统模块设计思路
- NSString 字符串 操作 常用
- mysql int类型的长度值
- Spark(二): 内存管理
- textarea在IE中和FF下不同的效果
- 用C++实现跨平台游戏开发之Irrlicht引擎
- python内turtle库应用
- vscode预览html插件,VSCode插件推荐-VSCode内嵌浏览器插件-Browser Preview
- 生态建设发展势头迅猛,OKB未来价值空间广阔
- 四川省2021年卫生副高考试成绩查询时间,四川省2021年卫生资格考试成绩查询时间:6月4日起...
- 面向初学者的高阶组件介绍
- 手机安装app总是显示未安装
- 【心电检测】基于 EMD、CEEMDAN 算法实现呼吸心跳信号检测实例(去除呼吸旁瓣干扰,测量心跳频率)附matlab代码
- 1. 大型网站架构演化
- Ps4手柄隐藏无法识别,PS4手柄没反应
- 游戏设计-《游戏改变世界》-思维导图
- WPF实现蜘蛛纸牌游戏
- [总结] 漫谈HDR和色彩管理(四)HDR标准和ACES
热门文章
- 大型计算机变形,计算机变形病毒的主要特征和发展趋势
- php判断记录,PHP判断数据库中的记录是否存在的方法,php数据库_PHP教程
- html 访问节点,HTML DOM 访问节点
- td 双击 编辑 php,双击表格td进行编辑
- php解密 码表,php拼音码表的生成
- 如何查看注解实现_该怎么运用注解呢?Java团队元老有话说
- java epoll select_字节跳动高频面试题,操作系统/算法/Java等。
- 《MySQL——数据表设计三大范式》
- 微信小程序 查找兄弟节点_使用C ++程序在链接列表中查找节点
- 关于Tomcat端口8080占用问题(解决方法)