activity_radio_button.xml

<?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"
>
<RadioGroup
android:id="@+id/rg_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/rd_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"
android:textSize="30sp"
android:textColor="#FF6600"/>
<RadioButton
android:id="@+id/rd_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
android:textSize="30sp"
android:textColor="#FF6600"/>
</RadioGroup>
<RadioGroup
android:id="@+id/rg_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rg_1"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rd_3"
android:layout_width="100dp"
android:layout_height="40dp"
android:button="@null"
android:text="男"
android:checked="true"
android:gravity="center"
android:background="@drawable/btn_41"
android:textSize="30sp"
android:textColor="#000000"/>
<RadioButton
android:id="@+id/rd_4"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="女"
android:gravity="center"
android:button="@null"
android:textSize="30sp"
android:background="@drawable/btn_41"
android:textColor="#000000"/>
</RadioGroup>
</RelativeLayout>

 

RadioButtonActivity。java

实现按钮的监听事件

package com.example.helloworld;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
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= (RadioGroup) findViewById(R.id.rg_1);
mRg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
RadioButton radioButton=group.findViewById(checkedId);
Toast.makeText(RadioButtonActivity.this, radioButton.getText(), Toast.LENGTH_SHORT).show();
}
});
}
}

  

效果

RadioButtton的更多相关文章

  1. Android UI-仿微信底部导航栏布局

    现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢.我们开发的主要的还是讲的是如何如 ...

随机推荐

  1. ansible roles实践——服务器初始化

    1.服务器初始化可以做哪些工作 关闭selinux ntp同步时间 修改dns为自建dns 配置ssh互信 修改yum源 设置主机名 内核参数优化 安装jdk 2.roles编写

  2. 进程(守护进程--互斥锁--IPC机制--生产者模型--僵尸进程与孤儿进程--模拟抢票--消息队列)

    目录 一:进程理论知识 1.理论知识 二:什么是进程? 三:僵尸进程与孤儿进程 1.僵尸进程 四:守护进程 1.什么是守护进程? 2.主进程创建守护进程 3.守护进程 五:互斥锁(模拟多人抢票) 1. ...

  3. Android开发-页面绘制

    今天主要绘制了记账页面 记账页面用到的布局是TableLayout加Viewpager联动的方式,通过设置一个标题头可以实现页面的左右滑动,viewpager中添加两个fragment. 需要制作两个 ...

  4. 微服务架构 | 7.2 构建使用 JWT 令牌存储的 OAuth2 安全认证

    目录 前言 1. JWT 令牌存储基础知识 1.1 JSON Web Token 2. 构建使用 JWT 令牌存储的 OAuth2 服务器 2.1 引入 pom.xml 依赖文件 2.2 创建 JWT ...

  5. 计算机网络再次整理————tcp例子第二前奏[四]

    前言 前文我们介绍了网络协议的各层,同时也介绍了一下我们在编写代码时候的服务端的accept.bind.listen.connect.send做了什么. 可以说是从宏观的角度,或者代码开发的角度来说的 ...

  6. PyTorch 介绍 | BUILD THE NEURAL NETWORK

    神经网络由对数据进行操作的layers/modules组成.torch.nn 命名空间提供了所有你需要的构建块,用于构建你自己的神经网络.PyTorch的每一个module都继承自nn.Module. ...

  7. JVM 问题分析思路

    1. 前言 工作中有可能遇到 java.lang.OutOfMemoryError: Java heap space 内存溢出异常, 本文提供一些内存溢出的分析及解决问题的思路. 常见异常如下: 20 ...

  8. Java高质量博文链接集合

    1. 看完这个,Java IO从此不在难 https://www.jianshu.com/p/715659e4775f 2. Java 8 中的 Streams API 详解 https://www. ...

  9. kali中安装arpspoof 报错

    情境今天在使用arpspoof这个命令的时候,提示没有命令找不到,此时就想着安装一下没想到,碰上kali源不支持的问题  解决所以,此时需要做的就是安装阿里云或者其他镜像  步骤1. vim /etc ...

  10. 简单的JSON数组转树形结构

    function toTree(data) { let result = [] if(!Array.isArray(data)) { return result } data.forEach(item ...