【Android】学习day05|RadioButton
注意事项:当使用默认选中标签:check时,必须要给标签加id,否则失效。
这个没什么,挺简单的,就记录一下代码【监听事件】
package com.example.app02; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast; public class RadioButtonActivity extends AppCompatActivity {
private RadioGroup mRg1; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_button);
mRg1=findViewById(R.id.rg_1);
mRg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
RadioButton radioButton=radioGroup.findViewById(i);
Toast.makeText(RadioButtonActivity.this, radioButton.getText(), Toast.LENGTH_SHORT).show();
}
}); }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<RadioGroup
android:id="@+id/rg_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/rb_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"
android:textSize="25sp"
android:textColor="#FF0000"/>
<RadioButton
android:id="@+id/rb_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
android:textColor="#FF0000"
android:textSize="25dp"/>
</RadioGroup>
<RadioGroup
android:id="@+id/rg_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/rg_1"
android:layout_marginTop="50dp">
<RadioButton
android:id="@+id/rb_3"
android:layout_width="60dp"
android:layout_height="30dp"
android:button="@null"
android:text="男"
android:checked="true"
android:textSize="25sp"
android:textColor="#fff"
android:background="@drawable/bg_pink"/>
<RadioButton
android:id="@+id/rb_4"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="女"
android:textColor="#fff"
android:textSize="25dp"
android:button="@null"
android:layout_marginLeft="10dp"
android:background="@drawable/bg_pink"/>
</RadioGroup>
</RelativeLayout>
【Android】学习day05|RadioButton的更多相关文章
- android学习之RadioButton和CheckBox
移通152 余继彪 RadioBuuton是一个单选按钮,CheckBox是一个复选按钮 . RadioButton的使用 ,首先要将RadioButton放在RadioGroup中,RadioGro ...
- android学习日记03--常用控件checkbox/radiobutton
常用控件3.checkbox 复选框,确定是否勾选,点击一下勾选,点击第二下取消,当有一系列备选项时适合用checkbox控件,方便用户提交数据. 贴上例子Activity的java代码 packag ...
- Android的RadioButton和checkBox的用法-android学习之旅(十九)
RadioButton和checkBox简介 单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:che ...
- Android学习之RadioGroup和RadioButton
转载自:http://my.oschina.net/amigos/blog/59261 实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioG ...
- Android学习路线总结,绝对干货
title: Android学习路线总结,绝对干货 tags: Android学习路线,Android学习资料,怎么学习android grammar_cjkRuby: true --- 一.前言 不 ...
- 【Android学习】《Android开发视频教程》第一季笔记
视频地址: http://study.163.com/course/courseMain.htm?courseId=207001 课时5 Activity基础概念 1.Android开发技术结构 ...
- 五、Android学习第四天补充——Android的常用控件(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 五.Android学习第四天补充——Android的常用控件 熟悉常用的A ...
- android学习--radiogroup学习
这个阶段在学习android的相关基本UI现将相关练习的代码粘贴在此便于后期学习之用(radio控件) 效果图: main_layout.xml <?xml version="1. ...
- android学习系列:jercy——AI3 的博客
[android学习之十七]——特色功能2:桌面组件(快捷方式,实时文件夹) 二.桌面组件 1.快捷方式 Android手机上得快捷方式的意思可以以我们实际PC机器上程序的快捷方式来理解.而andro ...
- Android学习笔记⑤——UI组件的学习TextView相关
TextView是一个强大的视图组件,直接继承了View,同时也派生出了很多子类,TextView其作用说白了就是在布局中显示文本,有点像Swing编程中的JLabel标签,但是他比JLabel强大的 ...
随机推荐
- Linux字符界面安装更新VMware Tools
注:yeesn为我自己的用户名,实际操作中改用自己的用户名 1.切换到虚拟光驱目录 cd /media/yeesn/VMware Tools 2.复制压缩包到桌面 cp VMwareTools-xxx ...
- IDApython的学习
IDApython的学习 我的IDA情况:IDA7.7,idapython3.8 这个可以作为文件导入和命令行内输入,我一般习惯命令行 这里要注意是python不是IDC 访问原数据 idc.get_ ...
- Prism报错
Rules.Default..WithoutFastExpressionCompiler()报错 说没有找到容器 1.查看Prism.Wpf源码 获取DryIoc容器规则 2.证明项目中出现了另外一个 ...
- c++算法之动态规划:01背包
什么是动态规划? 动态规划算法(dynamic programing),是一种由递推为基础的比贪心更稳定的一种优化策略,为运筹学的一部分.就是通过以递推为基础的手段非暴力求出最值. 它的总体思想其实就 ...
- role
角色权限管理改造方案 # 为什么需要角色 现有的权限方案 .net后台权限管理 在后台类中配置,权限 = 一级菜单:二级菜单:三级菜单: 通过在view模板中判断是否有权限显示菜单 后端通过权限配 ...
- iFiles浏览iphone文件
我们希望能在iphone中浏览文件系统的目录
- 文心一言 VS 讯飞星火 VS chatgpt (91)-- 算法导论8.3 4题
四.用go语言,说明如何在 O(n) 时间内,对 0 到 $n^3-1$ 区间内的n个整数进行排序. 文心一言: 在 O(n) 时间内对 0 到 n^3-1 区间内的 n 个整数进行排序,可以使用基数 ...
- 「luogu - P4313」文理分科 Mincut
link. Pretty nice practice for the min-cut trick. Starting out we eliminate the constraint that if f ...
- 【matplotlib基础】--3D图形
matplotlib 在1.0版本之前其实是不支持3D图形绘制的. 后来的版本中,matplotlib加入了3D图形的支持,不仅仅是为了使数据的展示更加生动和有趣.更重要的是,由于多了一个维度,扩展了 ...
- MySQL 高级(进阶) SQL 语句
MySQL 高级(进阶) SQL 语句 use gy; create table location (Region char(20),Store_Name char(20)); insert into ...