自定义RadioButton样式1
来源:互联网 发布:客户数据分析表 编辑:程序博客网 时间:2024/05/09 14:39
主要是布局:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <RadioGroup android:gravity="center"
- android:layout_gravity="bottom"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <RadioButton
- android:id="@+id/btn_0"
- android:textSize="17.0sp"
- android:textColor="@android:color/black"
- android:text="搜索微博"
- android:layout_weight="1"
- android:button="@null"
- android:checked="true"
- android:drawableLeft="@drawable/state_radio"
- android:background="@drawable/state_btn"
- android:gravity="center_vertical"
- >
- </RadioButton>
- <RadioButton
- android:id="@+id/btn_1"
- android:textSize="17.0sp"
- android:textColor="@android:color/black"
- android:text="搜索用户"
- android:layout_weight="1"
- android:button="@null"
- android:drawableLeft="@drawable/state_radio"
- android:background="@drawable/state_btn"
- android:gravity="center_vertical"
- >
- </RadioButton>
- </RadioGroup>
- </LinearLayout>
其中state_radio.xml
- <?xml version="1.0" encoding="utf-8"?>
- <selector
- xmlns:android="http://schemas.android.com/apk/res/android"
- >
- <item
- android:state_focused="false"
- android:state_checked="false"
- android:state_pressed="false"
- android:drawable="@drawable/bg_radio"
- >
- </item>
- <item
- android:state_focused="false"
- android:state_checked="true"
- android:state_pressed="false"
- android:drawable="@drawable/bg_radio_selected"
- >
- </item>
- <item
- android:state_focused="true"
- android:state_checked="false"
- android:state_pressed="false"
- android:drawable="@drawable/bg_radio_onfocus"
- >
- </item>
- <item
- android:state_focused="true"
- android:state_checked="true"
- android:state_pressed="false"
- android:drawable="@drawable/bg_radio_onfocus_selected"
- >
- </item>
- </selector>
state_btn.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_window_focused="false"
- android:drawable="@drawable/bg_btn"/>
- <item android:state_focused="true" android:state_pressed="true"
- android:drawable="@drawable/bg_btn_selected" />
- <item android:state_focused="false" android:state_pressed="true"
- android:drawable="@drawable/bg_btn_selected" />
- </selector>
上面的写法有点拖沓,采用style可能会更简单:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <style name="CustomTheme" parent="android:Theme">
- <item name="android:radioButtonStyle">@style/RadioButton</item>
- </style>
- <style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
- <item name="android:button">@drawable/radio</item>
- </style>
- </resources>
radio.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_checked="true" android:state_window_focused="false"
- android:drawable="@drawable/radio_hover" />
- <item android:state_checked="false" android:state_window_focused="false"
- android:drawable="@drawable/radio_normal" />
- <item android:state_checked="true" android:state_pressed="true"
- android:drawable="@drawable/radio_active" />
- <item android:state_checked="false" android:state_pressed="true"
- android:drawable="@drawable/radio_active" />
- <item android:state_checked="true" android:state_focused="true"
- android:drawable="@drawable/radio_hover" />
- <item android:state_checked="false" android:state_focused="true"
- android:drawable="@drawable/radio_normal_off" />
- <item android:state_checked="false" android:drawable="@drawable/radio_normal" />
- <item android:state_checked="true" android:drawable="@drawable/radio_hover" />
- </selector>
如何进行Radio Button Group的管理 参见 :
http://www.iteye.com/topic/1116261
- 自定义RadioButton样式1
- 自定义RadioButton样式1
- RadioButton - android 自定义RadioButton样式
- 自定义RadioButton样式
- RadioButton自定义样式
- android 自定义RadioButton样式
- 自定义RadioButton样式2
- 自定义RadioButton样式
- 自定义RadioButton样式2
- android 自定义RadioButton样式
- Android 自定义RadioButton样式
- 如何自定义RadioButton样式
- Android自定义RadioButton样式
- android 自定义RadioButton样式
- 如何自定义RadioButton样式
- radiobutton设置自定义样式
- android 自定义RadioButton样式
- android 自定义RadioButton样式
- Aptana Studio 3 如何汉化,实现简体中文版
- 使用parseexcel Ruby读取Excel
- Java Socket多线程服务端、客户端
- 2.rotation
- 屏幕取词
- 自定义RadioButton样式1
- android自定义 BaseAdapter
- SimpleDateFormat
- Unix/Linux IPC及线程间通信总结
- 无法解析的外部符号 _main解决办法
- Kmp字符串匹配算法改进版
- vs2010未能找到路径 \csharp\1033\WebForm.Zip\WebForm.vstemplate
- [Android] ImageView.ScaleType设置图解
- windbg双机调试时对R3函数下断