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来做的.那到底怎么做,接下来我就做一下分享!希望看了之后你也觉 ...
随机推荐
- 这才是真正的裸眼3D!超级震撼!!
大家有没认为有意思啦,反正俺是被震撼到了. 好奇异-- ! " src="http://www.yixieshi.com/uploads/allimg/141116/1446431 ...
- 大杂烩 -- equals、hashCode联系与区别
基础大杂烩 -- 目录 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Equals 1.默认情况(没有覆盖equals方 ...
- vue跨域代理配置
实际:http://a.com/b.php 代理:http://localhost/b.php 配置config/index.js proxyTable: { '/api': { target:'ht ...
- c++11 auto 与 decltype 详解
转自: here 一. auto简介 编程时候常常需要把表达式的值付给变量,需要在声明变量的时候清楚的知道变量是什么类型.然而做到这一点并非那么容易(特别是模板中),有时候根本做不到.为了解决这个问题 ...
- [原]jenkins(六)---jenkins远程部署脚本
/** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...
- ftp服务器Serv-U 设置允许自动创建不存在的目录
一.由来 最近改写了项目中ftp上传部分的代码. 用到的组件为: <dependency> <groupId>commons-net</groupId> <a ...
- Unity3D 批处理场景的工具
//场景的批量处理器 public static class OperateScene { public const string SceneDir = "Assets/Scene/&quo ...
- 10.10xadmin
2018-10-10 15:11:55 这几天讲的是xadmin插件 就是把表单,数据内容封装到类里面,简化的增删改查步骤! 放上源代码: app01/xadim.py from django.con ...
- D - Football (aka Soccer)
Football the most popular sport in the world (americans insist to call it "Soccer", but we ...
- MINIUI后台获取数据
1.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...