Android按钮_单选框_多选框_文字框
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 tools:context=".MainActivity"
7 android:orientation="vertical">
8
9
10 <!-- 多选框-->
11 <CheckBox
12 android:id="@+id/cb_cg"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:text="唱歌"
16 android:checked="true"
17 >
18 </CheckBox>
19 <CheckBox
20 android:id="@+id/cb_gm"
21 android:layout_width="wrap_content"
22 android:layout_height="wrap_content"
23 android:text="打游戏"
24 android:checked="false"
25 >
26 </CheckBox>
27
28
29 <!-- 布局文件调用OnClick函数:-->
30 <Button
31 android:layout_width="wrap_content"
32 android:layout_height="wrap_content"
33 android:background="@drawable/select_login_btn"
34 android:onClick="login"
35 />
36 <!--匿名内部类方式-->
37 <Button
38 android:id="@+id/btn2"
39 android:layout_width="wrap_content"
40 android:layout_height="wrap_content"
41 android:textSize="30sp"
42 android:text="匿名内部类方式"
43 />
44
45 <EditText
46 android:id="@+id/ed01"
47 android:layout_width="match_parent"
48 android:layout_height="wrap_content"
49 android:hint="(提示内容)只可以输入数字"
50 android:inputType="number"
51 android:text=""
52 android:textColor="@android:color/background_dark"
53 android:textColorHint="@android:color/holo_green_light" />
54
55 <EditText
56 android:id="@+id/ed02"
57 android:layout_width="match_parent"
58 android:layout_height="wrap_content"
59 android:hint="输入密码"
60 android:text=""
61 android:textColor="@android:color/background_dark"
62 android:textColorHint="@android:color/holo_green_light"
63 />
64 <ImageView
65 android:layout_width="60dp"
66 android:layout_height="wrap_content"
67 android:background="@android:drawable/btn_dialog"
68 />
69
70 <!--
71 inputType
72 number:数字
73 numberPassword:数字密码
74 text:文本
75 password:文字密码
76 phone:手机号
77 email:邮箱
78 date:日期
79 -->
80 <RadioGroup
81 android:id="@+id/rg_gender"
82 android:layout_width="wrap_content"
83 android:layout_height="wrap_content"
84 android:orientation="vertical"
85 >
86 <RadioButton
87 android:id="@+id/male"
88 android:layout_width="wrap_content"
89 android:layout_height="wrap_content"
90 android:text="男"
91 />
92 <RadioButton
93 android:id="@+id/female"
94 android:layout_width="wrap_content"
95 android:layout_height="wrap_content"
96 android:text="女"/>
97 </RadioGroup>
98 <!-- RadioButton和RadioGroup必须一起使用-->
99 <RadioGroup
100 android:layout_width="wrap_content"
101 android:layout_height="wrap_content"
102 android:orientation="horizontal"
103 >
104 <RadioButton
105 android:layout_width="wrap_content"
106 android:layout_height="wrap_content"
107 android:text="2000"
108 />
109 <RadioButton
110 android:layout_width="wrap_content"
111 android:layout_height="wrap_content"
112 android:text="2001"/>
113 </RadioGroup>
114
115
116
117
118 </LinearLayout>
Activity
1 package com.example.myapplication;
2
3 import android.os.Bundle;
4 import android.util.Log;
5 import android.view.View;
6 import android.widget.Button;
7 import android.widget.CheckBox;
8 import android.widget.CompoundButton;
9 import android.widget.EditText;
10 import android.widget.RadioGroup;
11 import android.widget.Toast;
12
13 import androidx.appcompat.app.AppCompatActivity;
14
15 public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
16
17
18 @Override
19 protected void onCreate(Bundle savedInstanceState) {
20 super.onCreate(savedInstanceState);
21 setContentView(R.layout.activity_btn);
22 final Button btn2;
23 final EditText ed01=findViewById(R.id.ed01);
24 final EditText ed02=findViewById(R.id.ed02);
25 btn2 = findViewById(R.id.btn2);
26 btn2.setOnClickListener(new View.OnClickListener() {
27 public void onClick(View v) {
28 Log.i("MainActivity", "匿名内部类按钮被点击");
29 Log.i("ed01", ed01.getText().toString());
30 Log.i("ed02", ed02.getText().toString());
31 /*
32 <!-- toast的使用 -->
33 1 makeText(context , text , duration)创建提示框不显示,必须加上.show()方法才会显示出来
34
35 (1)context
36 必须是一个activity
37 就是写 Activity.this
38 上下文
39 凡是眼睛看得见的东西都和上下文有关
40 (2)text
41 显示的内容
42 (3)duration
43 显示时间
44 Toast.LENGTH.SHORT:1秒,实际值是0
45 LENGTH.LONG:2秒,实际值是1秒
46 2 show()
47 显示提示框
48 */
49 Toast.makeText(MainActivity.this,"这是显示的内容",Toast.LENGTH_SHORT).show();
50 }
51 });
52 RadioGroup rg_gender = findViewById(R.id.rg_gender);
53 final CheckBox cb_cg=findViewById(R.id.cb_cg);
54 cb_cg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
55 @Override
56 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
57 /*
58 buttonView :被点击的控件
59 isChecked:复选框是否被选中
60
61 */
62 Log.i("onCheckedChanged",cb_cg.getText().toString()+(isChecked?"被选中":"取消选中"));
63 }
64 });
65 rg_gender.setOnCheckedChangeListener(this);
66
67 }
68
69 public void login(View v){
70 Log.i("MainActivity","按钮被点击");
71 }
72
73 @Override
74 public void onCheckedChanged(RadioGroup group, int checkedId) {
75 switch (checkedId)
76 {
77 case R.id.male:
78 Log.i("onCheckedChanged","男");
79 case R.id.female:
80 Log.i("OnCheckedChanged","女");
81 }
82 }
83
84
85
86 }
87 /*
88 java 变量
89 1、作用:保存数据,使用方便
90 2、作用域:有效范围,大括号
91 3、变量分类:
92 1.属性
93 实例属性
94 格式:
95 权限修饰符 返回值类型 方法名(方法形参列表) {方法体}
96 静态属性
97 常量
98 2.局部变量
99 */
100
101
102 /*
103 按钮点击事件
104 1、只可以写在java文件里面
105 2、点击时间的方法
106 (1)public void 方法名(View v)
107 方法名可以自定义
108 */
package com.example.myapplication;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_btn);
final Button btn2;
final EditText ed01=findViewById(R.id.ed01);
final EditText ed02=findViewById(R.id.ed02);
btn2 = findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("MainActivity", "匿名内部类按钮被点击");
Log.i("ed01", ed01.getText().toString());
Log.i("ed02", ed02.getText().toString());
/*
<!-- toast的使用 -->
1 makeText(context , text , duration)创建提示框不显示,必须加上.show()方法才会显示出来
(1)context
必须是一个activity
就是写 Activity.this
上下文
凡是眼睛看得见的东西都和上下文有关
(2)text
显示的内容
(3)duration
显示时间
Toast.LENGTH.SHORT:1秒,实际值是0
LENGTH.LONG:2秒,实际值是1秒
2 show()
显示提示框
*/
Toast.makeText(MainActivity.this,"这是显示的内容",Toast.LENGTH_SHORT).show();
}
});
RadioGroup rg_gender = findViewById(R.id.rg_gender);
final CheckBox cb_cg=findViewById(R.id.cb_cg);
cb_cg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
/*
buttonView :被点击的控件
isChecked:复选框是否被选中
*/
Log.i("onCheckedChanged",cb_cg.getText().toString()+(isChecked?"被选中":"取消选中"));
}
});
rg_gender.setOnCheckedChangeListener(this);
}
public void login(View v){
Log.i("MainActivity","按钮被点击");
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId)
{
case R.id.male:
Log.i("onCheckedChanged","男");
case R.id.female:
Log.i("OnCheckedChanged","女");
}
}
}
/*
java 变量
1、作用:保存数据,使用方便
2、作用域:有效范围,大括号
3、变量分类:
1.属性
实例属性
格式:
权限修饰符 返回值类型 方法名(方法形参列表) {方法体}
静态属性
常量
2.局部变量
*/
/*
按钮点击事件
1、只可以写在java文件里面
2、点击时间的方法
(1)public void 方法名(View v)
方法名可以自定义
*/
Android按钮_单选框_多选框_文字框的更多相关文章
- Android开发之使用AlertDialog创建对话框,单选框和多选框
对话框: 对话框的icon,title,message等都可以不设置. 单选框和多选框与对话框勾选步骤基本上一致. 对话框的构建步骤: 1.使用AlertDialog类的内部类Builder类new ...
- [SAP ABAP开发技术总结]选择屏幕——按钮、单选复选框
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Android笔记(十五) Android中的基本组件——单选框和复选框
单选框和多选框通常用来在设置用户个人资料时候,选择性别.爱好等,不需要用户直接输入,直接在备选选项中选择,简单方便. 直接看代码: <?xml version="1.0" e ...
- Android Studio常见对话框(普通对话框、单选对话框、多选对话框、进度条对话框、消息对话框、自定义对话框)
Android Studio常见对话框(普通对话框.单选对话框.多选对话框.进度条对话框.消息对话框.自定义对话框) 1.普通对话框 2.单选对话框 3.多选对话框 4.进度条对话框 5.消息对话框 ...
- Android系统--输入系统(九)Reader线程_核心类及配置文件
Android系统--输入系统(九)Reader线程_核心类及配置文件 1. Reader线程核心类--EventHub 1.1 Reader线程核心结构体 实例化对象:mEventHub--表示多个 ...
- Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析
Android系统--输入系统(十)Reader线程_核心类及配置文件深入分析 0. 前言 个人认为该知识点阅读Android源代码会不仅容易走进死胡同,并且效果并不好,前脚看完后脚忘记,故进行总结, ...
- CSS学习笔记三:自定义单选框,复选框,开关
一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...
- vue.js实现单选框、复选框和下拉框
Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框 在传统的HTM ...
- html基本标签表单实现交互原理,单选框,复选框,下拉框介绍
表单是什么?表单是前端和服务器做交互的一种机制,表单收集用户输入信息,之后发送或者提交给服务器.用户在输入的信息称之为内容,内容的文本分为普通和密码型,用户通过单选框.复选框.下拉框(也就是下拉菜单) ...
- 省选加油>_<
今天没有写题诶……看了看以前的模板……明天就要省选了>_<加油~~ 要不再去打局dota吧>_>
随机推荐
- oracle sqlplus命令详解(官方示例)
以为内容选自Oracle官方文档,只讲command-line: 规范:<变量名> , {举例} , a | b 枚举可选值,(XX)描述 ------------------------ ...
- Go语言并发编程(3):sync包介绍和使用(上)-Mutex,RWMutex,WaitGroup,sync.Map
一.sync 包简介 在并发编程中,为了解决竞争条件问题,Go 语言提供了 sync 标准包,它提供了基本的同步原语,例如互斥锁.读写锁等. sync 包使用建议: 除了 Once 和 WaitGro ...
- collections模块下的defaultdict用法
defaultdict from collections import defaultdict s=[('yellow',1),('blue', 2), ('yellow', 3), ('blue', ...
- 前后端分离解决跨域cors问题
修改windows的hosts文件 vim C:\Windows\System32\drivers\etc\hosts 添加域名 前端:www.luffycity.cn 后端:api.luffycit ...
- git 多系统复用账号
重装系统前请备份~/.ssh下的公钥私钥文件,重装系统后,请使用以下方法复用好之前的key 将备份好的key copy至~/.ssh下 将私钥id_rsa的文件属性改为600:sudo chmod 6 ...
- 1.Go 的基本数据类型
Go 的基本数据类型
- 【LeetCode二叉树#18】修剪二叉搜索树(涉及重构二叉树与递归回溯)
修剪二叉搜索树 力扣题目链接(opens new window) 给定一个二叉搜索树,同时给定最小边界L 和最大边界 R.通过修剪二叉搜索树,使得所有节点的值在[L, R]中 (R>=L) .你 ...
- offline RL | 读读 Decision Transformer
论文标题:Decision Transformer: Reinforcement Learning via Sequence Modeling,NeurIPS 2021,6 6 7 9 poster( ...
- SDWebImage从小白到大师蜕变
简介 SDWebImage提供的简洁的获取远程URL图片的API:平时开发中使用最多场景就是列表中的cell中要显示远程图片的需求,在具体的实现中要避免加载图片造成的界面卡顿,列表卡顿等现象的出现:所 ...
- 第134篇:解决浏览器的CORS跨域问题(CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge.)
好家伙, 我继续尝试着将我的飞机大战使用ES6模块化分离开来,出了点问题 1.出现问题: edge,chrome等一系列浏览器,会为了安全,禁止你跨域访问 目录如下: 主程序 index.htm ...