【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强大的 ...
随机推荐
- IDApython的学习
IDApython的学习 我的IDA情况:IDA7.7,idapython3.8 这个可以作为文件导入和命令行内输入,我一般习惯命令行 这里要注意是python不是IDC 访问原数据 idc.get_ ...
- C++函数参数匹配规则
C++ 函数参数匹配 1 单个参数匹配 void f(); //f1 void f(int); //f2 void f(int, int); //f3 void f(double, double=3. ...
- python 自定义排序
需求:根据自定义的顺序就行排序 实现方法: res = [ {'name': 'RE', 'value': 2}, {'name': 'aa', 'value': 3}, {'name': 'RFM' ...
- WPF 在MVVM模式下应用动画
一个简单的需求:当程序发生异常时候,在界面上动画显示异常信息. 这个需求看似简单,只需要try--catch到异常,然后把异常的信息写入界面就OK了. 但在MVVM时,就不是这么简单了.MVVM模式下 ...
- 文盘Rust——子命令提示,提高用户体验
上次我们聊到 CLI 的领域交互模式.在领域交互模式中,可能存在多层次的子命令.在使用过程中如果全评记忆的话,命令少还好,多了真心记不住.频繁 --help 也是个很麻烦的事情.如果每次按 'tab' ...
- 实现WebRTC群聊会议室(Mesh方案)
近期需要做一个类似会议室功能,但网络上大多数是一对一通信,故记录分享希望帮助到有用的人 WebRTC一对一聊天原理 关于WebRTC建立一对一聊天的模板网上很多,可参考以下博客:springboot+ ...
- Solution Set -「CF 1514」
「CF 1514A」Perfectly Imperfect Array Link. 就看序列中是否存在不为平方数的元素即可. #include<bits/stdc++.h> using n ...
- 使用Debian 11基础镜像制作java8镜像
下面是dockerfile内容: FROM debian:bullseye # 切换apt源为清华源,并安装vim ping telnet命令 RUN apt-get update && ...
- jenkins更换国内插件源
sed -i 's/https:\/\/updates.jenkins.io\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' ...
- 3DMatch
详细描述链接:3DMatch 数据集.github(介绍非常详细) 官网主页: 主页 3DMatch数据集收集了来自于62个场景的数据,其中54个场景的数据用于训练,8个场景的数据用于评估,其具体名称 ...