Android定制RadioButton样式三种实现方法
更新时间:2013年02月21日 16:34:25 作者:
三种方法实现Android定制RadioButton样式:使用XML文件进行定义/在JAVA代码中定义等等,感兴趣的朋友可以参考下,希望可以帮助到你
三种方法
1.使用XML文件进行定义 res/drawable/radio.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 未选中->
<item
android:state_checked="false"
android:drawable="@drawable/tabswitcher_long" />
<!--选中->
<item
android:state_checked="true"
android:drawable="@drawable/tabswitcher_short" />
</selector>
在布局文件中使用
<RadioGroup
...
>
<RadioButton
...
android:button="@null"
android:background="@drawable/radio"
/>
</RadioGroup>
ndroid:button="@null" 去除RadioButton前面的圆点
android:background="@drawable/radio" 使用定义的样式
2.在JAVA代码中定义
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
this.setBackgroundResource(com.wxg.tab.R.drawable.main_bg);
}else if(event.getActionMasked()== MotionEvent.ACTION_DOWN) {
this.setBackgroundResource(com.wxg.tab.R.drawable.hui);
}
return super.onTouchEvent(event);
}
去除RadioButton前面的圆点adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定义,在JAVA代码中使用 radioButton.setBackgroundResource(R.drawable.radio);调用
1.使用XML文件进行定义 res/drawable/radio.xml
复制代码 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 未选中->
<item
android:state_checked="false"
android:drawable="@drawable/tabswitcher_long" />
<!--选中->
<item
android:state_checked="true"
android:drawable="@drawable/tabswitcher_short" />
</selector>
在布局文件中使用
复制代码 代码如下:
<RadioGroup
...
>
<RadioButton
...
android:button="@null"
android:background="@drawable/radio"
/>
</RadioGroup>
ndroid:button="@null" 去除RadioButton前面的圆点
android:background="@drawable/radio" 使用定义的样式
2.在JAVA代码中定义
复制代码 代码如下:
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
this.setBackgroundResource(com.wxg.tab.R.drawable.main_bg);
}else if(event.getActionMasked()== MotionEvent.ACTION_DOWN) {
this.setBackgroundResource(com.wxg.tab.R.drawable.hui);
}
return super.onTouchEvent(event);
}
去除RadioButton前面的圆点adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定义,在JAVA代码中使用 radioButton.setBackgroundResource(R.drawable.radio);调用
您可能感兴趣的文章:
- Android单选按钮RadioButton的使用详解
- Android控件RadioButton实现多选一功能
- Android开发设置RadioButton点击效果的方法
- Android编程实现自定义PopupMenu样式示例【显示图标与设置RadioButton图标】
- Android RadioButton 图片位置与大小实例详解
- Android RadioGroup和RadioButton控件简单用法示例
- Android中设置RadioButton在文字右边的方法实例
- android RadioButton和CheckBox组件的使用方法
- Android RadioButton单选框的使用方法
- Android控件系列之RadioButton与RadioGroup使用方法
- Android控件RadioButton的使用方法
相关文章
Android自定义下拉刷新控件RefreshableView
这篇文章主要介绍了Android自定义下拉刷新控件RefreshableView,支持所有控件的下拉刷新,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-11-11Android在fragment中编写toobar的步骤详解
这篇文章主要介绍了Android在fragment中编写toobar,本文分步骤通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2021-01-01详解Android Automotive车载应用对驾驶模式Safe Drive Mode的适配
这篇文章主要介绍了详解Android Automotive车载应用对驾驶模式(Safe Drive Mode)的适配,对车载应用感兴趣的同学可以参考下2021-04-04Android 中ImageView的ScaleType使用方法
这篇文章主要介绍了Android 中ImageView的ScaleType使用方法的相关资料,希望通过本能帮助到大家,需要的朋友可以参考下2017-09-09Android组件TabHost实现页面中多个选项卡切换效果
这篇文章主要为大家详细介绍了Android组件TabHost实现页面中多个选项卡切换效果的相关资料,感兴趣的小伙伴们可以参考一下2016-05-05
最新评论