效果图如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/radiobutton_textview"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="@android:drawable/title_bar"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dip"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:paddingLeft="30dip"
android:text="Android新手"
android:textSize="20dip" />
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider" />
<RadioButton
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:paddingLeft="30dip"
android:text="Android高手"
android:textSize="20dip" />
</RadioGroup>
</LinearLayout>
package sdfasdf.sadf;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class SdfsadfasdfasdffActivity extends Activity {
private TextView textView;
private RadioGroup group;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.radiobutton_textview);
group = (RadioGroup) findViewById(R.id.group);
// 单选按钮组监听事件
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// 根据ID判断选择的按钮
if (checkedId == R.id.button1) {
textView.setText("Android新手");
} else {
textView.setText("Android高手");
}
}
});
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
分享到:
相关推荐
主要介绍了Android中设置RadioButton在文字右边的方法实例,本文直接给出XML配置实现代码,需要的朋友可以参考下
android中RadioButton的图标在左边,文字在右边,如何实现文字在左边,图标在右边? 第一步:将RadioButton自带的图标隐藏, 第二步:在隐藏图标的右边添加系统的图标 第三步:在隐藏图标的位置显示文字. 具体参考: ...
Android开发之RadioButton位于文字右边的显示方法更多可查看:https://blog.csdn.net/xiayiye5
android 自定义RadioButton的样式android 自定义RadioButton的样式
android 自定义 单选按钮 radioButton
原来在用android的TabHost生成的选项卡时有一定的局限性,它不能很好地用布局控制,而我转而采用android的RadioButton来生成选项卡并实现选项卡功能,并且这个代码还实现了ViewFlipper实现选项卡根据手势左右滑动的...
--xml 调用 <com.triman.android.ui.MyRadioButton android:id="@+id/rb_sys_set" android:layout_width="0dp" android:layout_height=...--设置值,显示气泡 rb_sys_set.setNumberDot(true,String.valueOf(ct));
自定义android RadioButton样式,代码说明地址:http://blog.csdn.net/jason_996/article/details/62889374
最近写项目有个需求是单选框必须改成设计要的样子,然后再网上找了好久,自己调试了一下,就好了
android Menu 和 RadioGroup RadioButton的用法
android组件 RadioButton,CheckBox,Toast简单介绍,
这是我自己的写的在listview里面使用radiobutton
tabhost原效果并不理想 这里利用button 改善
支持使用selector的自定义RadioButton
Android_实例_利用RadioButton实现分类筛选
android代码实现动态加载Radiobutton
安卓Android源码——(RadioButton与监听).zip
android自定义RadioButton,可用于竖直方向的tabhost组件的自定义设计,实现了tabWiget的效果。
主要介绍了Android开发设置RadioButton点击效果的方法,详细分析了Android开发中RadioButton属性功能及相关设置技巧,需要的朋友可以参考下