RadioButton使用
RadioButton和CheckBox差不多,这里只写一个,因为我本身不是学andorid,所以就当给自己留一个备份,省的每次用到都需要代码敲一次,很麻烦
1.如果想选中时想改变颜色可以设置一个xml,我设置的upload_state_btn
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#0000ff"></item>
<item android:color="#2a2a2a"></item>
</selector>
使用
<RadioGroup android:layout_width="match_parent"
android:layout_height="44dp"
android:orientation="horizontal"
android:id="@+id/group">
<RadioButton android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="男"
android:button="@null"
android:gravity="center"
android:checked="true"
android:enabled="false"
android:textColor="@drawable/upload_state_btn"
android:id="@+id/btn1"
/>
<RadioButton android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="女"
android:button="@null"
android:gravity="center"
android:textColor="@drawable/upload_state_btn"
android:id="@+id/btn2"/>
</RadioGroup>
点击事件有两种方法
方法一:
RadioGroup group = (RadioGroup)findViewById(R.id.group);
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.btn1:
break;
case R.id.btn2:
break;
}
}
});
方法二:
RadioButton btn1;
RadioButton btn2;
btn1 = (RadioButton)findViewById(R.id.btn1);
btn2 = (RadioButton)findViewById(R.id.btn2); btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent startIntent = new Intent(DemoActivity.this, MyService.class);
//startService启动形式
startService(startIntent); }
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent startIntent = new Intent(DemoActivity.this, MyService.class);
//startService启动形式
stopService(startIntent);
}
});
如果需要改变系统自带的图标,可以添加xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@mipmap/checkbox_role"
android:state_checked="true"/>
<item
android:drawable="@mipmap/checkbox_dis_role"
android:state_checked="false"/>
<item
android:drawable="@mipmap/checkbox_dis_role"/>
</selector>
在styles中添加:
<style name="CustomTheme" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:button">@drawable/custom_radio</item>
</style>
使用的使用直接在xml RadioButton属性中添加一句:
style="@style/CustomTheme"
RadioButton使用的更多相关文章
- RadioButton与CheckBox
笔者长期从事于数据库的开发,算了,不提当年了,因为一直用的是小语种(PowerBuilder),还是来说说这两个最常见的控件吧! RadioButton(单选)和CheckBox(多选) 先来看看继承 ...
- 【WPF】值是枚举的RadioButton 绑定问题
源 1.RadioButton 2.IValueConverter 3.枚举 xaml实现 <RadioButton Content="单打热身" GroupName=&qu ...
- Android RadioGroup和RadioButton详解
实现RadioButton由两部分组成,也就是RadioButton和RadioGroup配合使用.RadioGroup是单选组合框,可以容纳多个RadioButton的容器.在没有RadioGrou ...
- react native RadioButton(单选按钮)
刚刚写完这个多选按钮,我觉得没有单选的话,总会觉得有一点点不爽,因为在项目中我也没有用到单选,所以我没有好好研究源码,所以我在Github上找了一下,发现有一个挺好的,简单,不花哨. 在Github上 ...
- RadioButton(单选按钮)文字在按钮的左边
<RadioButton style="@style/CustomCheckboxTheme" android:layout_width="fill_parent& ...
- RadioGroup、RadioButton、CheckBox、Toast用法
xml布局文件如下: <RadioGroup android:id="@+id/sex" android:layout_width="wrap_content&qu ...
- 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
[源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...
- 转 Android RadioButton设置选中时文字和背景颜色同时改变
主要应用在购物车,像淘宝的那样,点击以后弹出一个选择种类颜色这样的popuwindow以后,然后这个选择种类的地方要用到类似这个玩意儿. 搜了一下,效果和这个文章一致.转了. 原文地址:http:// ...
- WPF中RadioButton绑定数据的正确方法
RadioButton一般用于单选的时候,也就是从一组值中选择一个值. 比如性别有“男”和“女”两种取值,而对于一个员工的实例来说,性别的取值要么是男,要么是女. 这种时候一般就会用到RadioBut ...
- Android-组件RadioButton使用技巧
当初第一次接触Android组件的时候,我感觉微信底部的菜单,是用button这样的组件来做的. 可我想错了.却是用RadioButton来做的.那到底怎么做,接下来我就做一下分享!希望看了之后你也觉 ...
随机推荐
- ViewPager PagerAdapter not updating the View
There are several ways to achieve this. The first option is easier, but bit more inefficient. Overri ...
- NLog类库的使用探索——认识配置+实习小感悟
1 写在前面 1.1 为什么学了软件 1.高考失败,分数不高,不能随心所欲 2.农村孩子,学点技术,将来有口饭吃 3.有科技含量,想玩电脑(那个时候是这么想的,那个时候觉得学计算机就是玩电脑) 1.2 ...
- Rsync实现多台Windows工作电脑文件同步
你要准备的软件有: 最新版 Rsync for windows 服务端:cwRsync_Server_2.1.5_Installer.zip 客户端:cwRsync_2.1.5_Installer.z ...
- 【死磕jeesite源码】Jeesite配置定时任务
一.主要是注意XML文件中设置3个地方和类文件中配置 第一步配置: 第二步配置:注解扫描 第三步配置:开启任务 类中注解配置:如下 @Service 或者Component @Lazy(false) ...
- Unity Editor工具-代码里复制Component
//CopyComponent ublic static T CopyComponent<T>(T original, GameObject destination) where T : ...
- 在windows下搭建vueJS开发环境
转自:https://www.cnblogs.com/RexSheng/p/6934413.html nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择 ...
- 2018GIAC全球互联网架构大会上海站最新日程抢先看!
2018年11月23-24日,为期两天的 GIAC全球互联网架构师大会将在上海拉开帷幕.GIAC全球互联网架构大会是由msup和高可用架构技术社区联合举办的面向架构师.技术负责人及高端技术从业人员的年 ...
- 7.26-STOIRegularMatch-08-#14
A-3 SRM 08 描述 给一个 01 串设为其 S,询问是否存在只出现两次的 01 串 T. 这里的出现定义为存在一串下标 ,满足 且 . 输入格式 一行,一个 01 串 输出格式 一行,字母 ...
- Deck of Cards ZOJ - 2852 dp 多决策 三维 滚动更新
题意:一个特殊21点游戏 具体http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2852 题解:建一个三维dp,表示三个卡槽分别 ...
- hive优化之开启压缩功能
1.开启hive作业mapreduce任务中间压缩功能: 对于数据进行压缩可以减少job中map和reduce task间的数据传输量.对于中间数据压缩,选择一个低cpu开销编/解码器要不选择一个压缩 ...