总结一下设置图标的三种方式:

(1)button属性:主要用于图标大小要求不高,间隔要求也不高的场合。

(2)background属性:主要用于能够以较大空间显示图标的场合。

(3)drawableLeft属性:主要用于对图标与文字之间的间隔有要求的场合。

注意使用 background 或者 drawableLeft时 要设置 android:button="@null"

监听:

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {

}
});
1
2
3
4
5
6
7
下面是一个例子:
效果图:

布局文件: activity_radio_button.xml 中使用

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:button="@null"
android:checked="true"
android:drawablePadding="10dp"
android:drawableTop="@drawable/selback"
android:gravity="center_horizontal"
android:text="男"
android:textColor="#FF0033"
/>

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:button="@null"
android:drawablePadding="10dp"
android:drawableTop="@drawable/selback"
android:gravity="center_horizontal"
android:text="女"
android:textColor="#000000"
/>

</RadioGroup>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
选择器:selback.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@mipmap/on"/>
<item android:drawable="@mipmap/off"/>
</selector>
1
2
3
4
选择器用到的图片:

RadioButtonActivity 中监听选中

package rolechina.jremm.com.test4;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class RadioButtonActivity extends Activity {
private RadioGroup radioGroup;
private RadioButton radioButton1;
private RadioButton radioButton2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_radio_button);
radioGroup = findViewById(R.id.radioGroup);
radioButton1 = findViewById(R.id.radioButton1);
radioButton2 = findViewById(R.id.radioButton2);

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// 选中 文字 显示红色,没有选中显示黑色
if(radioButton1.isChecked()) {
radioButton1.setTextColor(Color.parseColor("#FF0033"));
}else{
radioButton1.setTextColor(Color.parseColor("#000000"));
}

if(radioButton2.isChecked()) {
radioButton2.setTextColor(Color.parseColor("#FF0033"));
}else{
radioButton2.setTextColor(Color.parseColor("#000000"));
}

}
});
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

---------------------

以JSONobject形式提交http请求的更多相关文章

  1. vue axios使用form-data的形式提交数据的问题

    vue axios使用form-data的形式提交数据vue axios request payload form data由于axios默认发送数据时,数据格式是Request Payload,而并 ...

  2. php ajax提交post请求出现数组被截断情况的解决方法

    一.场景 今天做保存专题商品列表的时候发现,前端明明有2300多条数据,但是实际服务端接受存入数据库才166条 二.解决过程 经过调试发现前端页面提交post请求时数据量是正确的,但到服务端只能接受到 ...

  3. Android 使用HttpClient方式提交POST请求

    final String username = usernameEditText.getText().toString().trim(); final String password = passwr ...

  4. Android 使用HttpClient方式提交GET请求

    public void httpClientGet(View view) { final String username = usernameEditText.getText().toString() ...

  5. 使用libcurl提交POST请求

    最近在学习libcurl,并利用它提交POST请求,可是返回的响应总是无从验证该次POST请求是否成功提交了. 1. 先看下根据firebug提交的一次成功的请求,这里以login我喜欢上的xiami ...

  6. jsonp形式的ajax请求:

    sonp形式的ajax请求:并且通过get请求的方式传入参数,注意:跨域请求是只能是get请求不能使用post请求 <!DOCTYPE html> <html> <hea ...

  7. EBS-如何查看非自己提交的请求的结果

    http://www.cnblogs.com/quanweiru/p/4692071.html 如何查看非自己提交的请求的结果定位要找的请求SQL举例:SELECT req.request_id,   ...

  8. EBS环境提交新请求默认是"单一请求"

    http://blog.csdn.net/samt007/article/details/38304239 用过EBS的请求都知道,提交一个新报表都要点好几个按钮,其中一个很麻烦的就是选择提交新请求的 ...

  9. 【转】提交http请求之python与curl

    提交http请求之python与curl 由于Openstack是python实现wsgi的REST ful架构,在学习和调试的过程中,常常会遇到http请求的提交,于是顺手整理下python和cur ...

随机推荐

  1. POJ1733 Parity game —— 种类并查集

    题目链接:http://poj.org/problem?id=1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  2. YTU 2432: C++习题 对象数组输入与输出

    2432: C++习题 对象数组输入与输出 时间限制: 1 Sec  内存限制: 128 MB 提交: 1603  解决: 1152 题目描述 建立一个对象数组,内放n(n<10)个学生的数据( ...

  3. Android ConstraintLayout的基本使用

    升级Android studio到2.3版本之后,发现新建Activity或fragment时,xml布局默认布局由RelativeLayout更改为ConstraintLayout了,既然已经推荐使 ...

  4. bzoj 1504 郁闷的出纳员

    题目大意: 有一些员工 他们有工资 当他们的工资低于一个值时 他们会永远离开 I命令 I_k 新建一个工资档案,初始工资为k.                 如果某员工的初始工资低于工资下界,他将立 ...

  5. [SCOI 2007] 修车

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1070 [算法] 首先 , 我们发现 , 在倒数第i个修车会对答案产生i * k的贡献 ...

  6. saltstack源码-启动3-config.py配置文件加载

    #目标文件位置/usr/lib/python2.6/site-packages/salt/config.py#这个文件加载配置文件的模块.master和minion的配置文件加载都是在这个模块里面完成 ...

  7. python ConfigParser模块 配置文件解析

    ConfigParser模块主要是用来解析配置文件的模块,像mysql,或者win下面的ini文件等等 下面我们来解析mysql的配置文件my.cnf my.cnf配置文件内容 [mysqld] da ...

  8. 在datagrid中,IE浏览器报错:SCRIPT5007: 无法获取属性“rowspan”的值: 对象为 null 或未定义

    项目总采用datagird时,产生界面如下图原本标题上有功能按钮,此时消失   错误:SCRIPT5007: 无法获取属性"rowspan"的值: 对象为 null 或未定义, 造 ...

  9. facebook chat api 使用

    官方API文档: https://developers.facebook.com/docs/chat/ 下面是根据文档修改的类: <?php class Invite_Chat{ protect ...

  10. php 和 js之间使用json通信

    有时候我们需要用后台从数据库中得到的数据在js中进行处理,但是当从php中获取到数据的时候,使用的是键值对形式的多维关联数组.而我们知道,js只支持索引数组,不支持关联数组,这个时候从后台传递过来的数 ...