RadioButtton
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的更多相关文章
- Android UI-仿微信底部导航栏布局
现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢.我们开发的主要的还是讲的是如何如 ...
随机推荐
- String类-intern方法
1 package cn.itcast.p1.string.demo; 2 3 class StringObjectDemo { 4 public static void main(String[] ...
- AOP-操作术语
AOP(术语) 1,连接点 类里面哪些方法可以被增强,这些方法称为连接点 2,切入点 实际被真正增强的方法,称为切入点 3,通知(增强) (1)实际增强的逻辑部分称为通知(增强) (2)通知有多种类型 ...
- vivo数据库与存储平台的建设和探索
本文根据Xiao Bo老师在"2021 vivo开发者大会"现场演讲内容整理而成.公众号回复[2021VDC]获取互联网技术分会场议题相关资料. 一.数据库与存储平台建设背景 以史 ...
- SIFT,SuperPoint在图像特征提取上的对比实验
SIFT,SuperPoint都具有提取图片特征点,并且输出特征描述子的特性,本篇文章从特征点的提取数量,特征点的正确匹配数量来探索一下二者的优劣. 视角变化较大的情况下 原图1 原图2 SuperP ...
- 用socket写一个简单的服务器
import socketsk=socket.socket()sk.bind(("127.0.0.1",7001))sk.listen()def login(url): with ...
- ExecutorService线程池简单使用
简介 ExecutorService是Java中对线程池定义的一个接口,它位于java.util.concurrent包中,在这个接口中定义了和后台任务执行相关的方法. 常用方法 public < ...
- 生成静态库.a文件和动态库.so文件
转载来源:https://www.cnblogs.com/hookjc/ 静态库 在linux环境中, 使用ar命令创建静态库文件.如下是命令的选项: d -----从指定的静态库文件中删除文件 m ...
- iOS App 架构文章推荐
iOS应用开发架构 iOS应用架构谈系列 阿里技术沙龙 2.2.1. Hybrid App 2.2.2. taobao 客户端架构 2.2.3. alipay 客户端架构 iOS APP 架构漫谈 ...
- iOS App程序内多语言国际化实现 By HL
iOS 多语言设置有很多方式可以实现,之前在做手机思埠1.0时,就对app进行了多语言设置,当时看到很多方法,比如用plist等方式保存键值对的,不过还是用Localisator来国际化最方便 1.添 ...
- CSS快速入门(四)
目录 CSS快速入门(四) 浮动 float属性 clear属性 浮动解决的问题及其影响 解决父标签塌陷的方法 浮动案例 定位 什么是脱离文档流 定位的两种方法 position定位 static定位 ...