安卓radiobutton 圆圈颜色选中状态 小圆圈怎么自定义设置颜色

怎么设置radio按钮选中颜色
怎么设置radio按钮选中颜色
写下你的评论...
Copyright (C)
All Rights Reserved | 京ICP备 号-2安卓中怎么通过代码设置RadioButton被选
最经在写安卓应用时,启动一个Activity类时,在onCreate()中设置RadioGroup中某个RadioButton被选,而该RadioButton中其他RadioButton改了好几次都没成功,怎么解决?求安卓开发能手?
QQ To Me:.
Thank You!
轻松打造安卓高级工程师打造会代码的全能UI设计师做被争抢的ios开发者
? ? ? ? ? ? ? ? ? ?
Powered by查看:19929|回复:3
最有价值午饭
又到周五了!RadioButton从字面上就可以很清楚的知道它是单选按钮,它与RadioGroup配套时候。通常我们在开发中需要自定义RadioButton的样式,比如新浪的Tab页,性别选择等都需要自定义一些漂亮的样式。
1、我们如何定制呢?
& && &首先我们先把RadioButton默认的单选按钮去掉。& && &只需要设置RadioButton的android:button=&@null&就可以了,@null就是把RadioButton默认的单选按钮去掉。
&&2、给你给RadioButton添加上你已经准备好了的图片或,你可以选择在RadioButton的左边或者右边添加图片,根据项目需要。
& && && &在按钮的左边添加图片
& && && && &android:drawableLeft=&@drawable/male&
& && && &在按钮的右边添加图片
& && && & android:drawableRight=&@drawable/radio_selector&
& && && & 按钮与描述文字之间的距离
& && && &&&android:drawablePadding=&10dip&复制内容到剪贴板代码:& && &&&&RadioGroup
& && && && &android:id=&@+id/radiogroup&
& && && && &android:layout_width=&fill_parent&
& && && && &android:layout_height=&wrap_content&
& && && && &androidrientation=&vertical& &
& && && && &&RadioButton
& && && && && & android:id=&@+id/yj_rb_sex_male&
& && && && && & android:layout_width=&fill_parent&
& && && && && & android:layout_height=&wrap_content&
& && && && && & android:background=&@drawable/radio_bg_selector&
& && && && && & android:button=&@null&
& && && && && & android:drawableLeft=&@drawable/male&
& && && && && & android:drawablePadding=&10dip&
& && && && && & android:drawableRight=&@drawable/radio_selector&
& && && && && & android:paddingBottom=&10dip&
& && && && && & android:paddingLeft=&20dip&
& && && && && & android:paddingRight=&20dip&
& && && && && & android:paddingTop=&10dip&
& && && && && & android:text=&男&
& && && && && & android:textColor=&#6D6D6D& /&
& && && && &&RadioButton
& && && && && & android:id=&@+id/yj_rb_sex_female&
& && && && && & android:layout_width=&fill_parent&
& && && && && & android:layout_height=&wrap_content&
& && && && && & android:background=&@drawable/radio_bg_selector&
& && && && && & android:button=&@null&
& && && && && & android:drawableLeft=&@drawable/female&
& && && && && & android:drawablePadding=&10dip&
& && && && && & android:drawableRight=&@drawable/radio_selector&
& && && && && & android:paddingBottom=&10dip&
& && && && && & android:paddingLeft=&20dip&
& && && && && & android:paddingRight=&20dip&
& && && && && & android:paddingTop=&10dip&
& && && && && & android:text=&女&
& && && && && & android:textColor=&#6D6D6D& /&
& && &&&&/RadioGroup&java代码如下复制内容到剪贴板代码:RadioGroup sexRroup = (RadioGroup) window.findViewById(R.id.radiogroup);
//设置单选按钮的选中事件
sexRroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
& & & & & & & & & & & &
& & & & & & & & & & & & public void onCheckedChanged(RadioGroup group, int checkedId) {
& & & & & & & & & & & & & & & & //这里做操作
& & & & & & & & & & & & }
& & & & & & & & });能力有限,请大家多多指点。
额,还打起广告了。
本帖最后由 xuzw13 于
11:15 编辑
:lol 多谢分享。
最有价值午饭
引用:原帖由 风泊海上 于
11:47 发表
:lol 多谢分享。 那个不是广告好不好!
引用:原帖由 xuzw13 于
12:36 发表
那个不是广告好不好! :lol :lol 啦啦啦,就是广告。。。Android 自定义RadioButton(单选按钮)图标随便定_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Android 自定义RadioButton(单选按钮)图标随便定
来源:Linux社区&
作者:jj120522
RadioButton在我们开发APP应用中是很常见的.这点我不用说大家也心知肚明.&
虽说 系统给我们提供了RadioButton但是为了我们的应用有种"与众不同"的效果,因为android的太死板太斯通见惯了.往往都会定制自己的图标.下面我给大家介绍一下我实现的方法:
方法:运用组合控件(ImageView and TextView)
组合控件代码:&
public&class&RadioButton&extends&LinearLayout&{&&
&&&&private&Context&&&
&&&&private&ImageView&imageV&&
&&&&private&TextView&textV&&
&&&&private&int&index&=&0;&&
&&&&private&int&id&=&0;&&
&&&&private&RadioButton&tempRadioB&&
&&&&private&int&state[]&=&{&R.drawable.radio_unchecked,&&
&&&&&&&&&&&&R.drawable.radio_checked&};&&
&&&&public&void&ChageImage()&{&&
&&&&&&&&index++;&&
&&&&&&&&id&=&index&%&2;&&
&&&&&&&&imageView.setImageResource(state[id]);&&
&&&&public&void&setText(String&text)&{&&
&&&&&&&&textView.setText(text);&&
&&&&public&String&getText()&{&&
&&&&&&&&return&id&==&0&?&""&:&textView.getText().toString();&&
&&&&public&RadioButton(Context&context)&{&&
&&&&&&&&this(context,&null);&&
&&&&public&RadioButton(Context&context,&AttributeSet&attrs)&{&&
&&&&&&&&super(context,&attrs);&&
&&&&&&&&this.context&=&&&
&&&&&&&&LayoutInflater.from(context).inflate(R.layout.item,&this,&true);&&
&&&&&&&&imageView&=&(ImageView)&findViewById(R.id.iv_item);&&
&&&&&&&&textView&=&(TextView)&findViewById(R.id.tv_item);&&
}&&上面的实现的很容易,所以不过多解释.
下面是调用代码:
public&class&MainActivity&extends&Activity&{&&
&&&&ListView&listV&&
&&&&@Override&&
&&&&public&void&onCreate(Bundle&savedInstanceState)&{&&
&&&&&&&&super.onCreate(savedInstanceState);&&
&&&&&&&&setContentView(R.layout.main);&&
&&&&&&&&listView&=&(ListView)&findViewById(R.id.lv_main);&&
&&&&&&&&listView.setAdapter(new&MyAdapter(this));&&
&&&&RadioButton&&&
&&&&class&MyAdapter&extends&BaseAdapter&{&&
&&&&&&&&private&Context&&&
&&&&&&&&private&LayoutInflater&&&
&&&&&&&&public&MyAdapter(Context&context)&{&&
&&&&&&&&&&&&super();&&
&&&&&&&&&&&&this.context&=&&&
&&&&&&&&&&&&inflater&=&LayoutInflater.from(context);&&
&&&&&&&&}&&
&&&&&&&&@Override&&
&&&&&&&&public&int&getCount()&{&&
&&&&&&&&&&&&return&10;&&
&&&&&&&&}&&
&&&&&&&&@Override&&
&&&&&&&&public&Object&getItem(int&position)&{&&
&&&&&&&&&&&&return&null;&&
&&&&&&&&}&&
&&&&&&&&@Override&&
&&&&&&&&public&long&getItemId(int&position)&{&&
&&&&&&&&&&&&return&0;&&
&&&&&&&&}&&
&&&&&&&&@Override&&
&&&&&&&&public&View&getView(int&position,&View&convertView,&ViewGroup&parent)&{&&
&&&&&&&&&&&&final&RadioButton&radioB&&
&&&&&&&&&&&&if&(convertView&==&null)&{&&
&&&&&&&&&&&&&&&&radioButton&=&new&RadioButton(context);&&
&&&&&&&&&&&&}&else&{&&
&&&&&&&&&&&&&&&&radioButton&=&(RadioButton)&convertV&&
&&&&&&&&&&&&}&&
&&&&&&&&&&&&radioButton.setText(position&+&"");&&
&&&&&&&&&&&&radioButton.setOnClickListener(new&OnClickListener()&{&&
&&&&&&&&&&&&&&&&@Override&&
&&&&&&&&&&&&&&&&public&void&onClick(View&v)&{&&
&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&if&(temp&!=&null)&{&&
&&&&&&&&&&&&&&&&&&&&&&&&temp.ChageImage();&&
&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&temp&=&radioB&&
&&&&&&&&&&&&&&&&&&&&radioButton.ChageImage();&&
&&&&&&&&&&&&&&&&&&&&Toast.makeText(context,&radioButton.getText(),&<FONT color=#c).show();&&
&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&});&&
&&&&&&&&&&&&return&radioB&&
&&&&&&&&}&&
}&&我来说明一下:我们首先创建一个temp模版,用于记忆你点击的那个RadioButton对象. &在你点击时候,首先查看temp是否为null,如果不为空则执行&temp.ChageImage(); 这个方法是取消选中效果.如果不为null,则首先对该RadioButton执行,取消该按钮选中状态.在执行你点击的那个RadioButton的ChageImage方法,最后记得要把当前的RadioButton付给temp.
效果是实现了,不过有个小问题,因为目前只有10条数据是看不出效果的.换成20条你就会发现很诡异的问题。
第15条数据会自动勾选上,找了又找,最后终于发现了,是因为listview 的问题。看下面:
final&RadioButton&radioB&&
&&&&&&&&&&&&if&(convertView&==&null)&{&&
&&&&&&&&&&&&&&&&radioButton&=&new&RadioButton(context);&&
&&&&&&&&&&&&}&else&{&&
&&&&&&&&&&&&&&&&radioButton&=&(RadioButton)&convertV&&
&&&&&&&&&&&&}&&
相关资讯 & & &
& (11/13/:33)
& (09/13/:16)
& (09/13/:32)
& (11/13/:11)
& (09/13/:53)
& (09/13/:15)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款15096人阅读
android(40)
主要是写一个 color selector
在res/建一个文件夹取名color
res/color/color_radiobutton.xml
&?xml version=&1.0& encoding=&utf-8&?&
&selector xmlns:android=&/apk/res/android&&
&item android:state_checked=&true& android:color=&@color/color_text_selected&/&
&!-- not selected --&
&item android:color=&@color/color_text_normal&/&
&/selector&
程序中就可以直接使用了
//layout/main.xml
&?xml version=&1.0& encoding=&utf-8&?&
&LinearLayout xmlns:android=&/apk/res/android&
android:layout_width=&fill_parent&
android:layout_height=&fill_parent&
android:orientation=&vertical& &
&RadioGroup
android:id=&@+id/radiogroup_personal_condition&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:orientation=&horizontal& &
&RadioButton
android:id=&@+id/radiobutton_1&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:background=&@drawable/selector_radio&
android:button=&@null&
android:checked=&true&
android:gravity=&center&
android:text=&目录&
android:textColor=&@color/color_radiobutton&
android:textSize=&@dimen/font_size&
android:textStyle=&bold& /&
&RadioButton
android:id=&@+id/radiobutton_2&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:background=&@drawable/selector_radio&
android:button=&@null&
android:gravity=&center&
android:text=&书签&
android:textColor=&@color/color_radiobutton&
android:textSize=&@dimen/font_size&
android:textStyle=&bold& /&
&/RadioGroup&
&/LinearLayout&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:165055次
积分:2236
积分:2236
排名:第11000名
原创:56篇
评论:60条
阅读:15102
阅读:38528
(1)(1)(1)(1)(4)(1)(1)(2)(5)(8)(6)(5)(4)(2)(6)(8)(2)(1)

我要回帖

更多关于 radiobutton 选中 的文章

 

随机推荐