自定義RadioButton樣式1
系統(tǒng)
1629 0
主要是布局:
<?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>
上面的寫(xiě)法有點(diǎn)拖沓,采用style可能會(huì)更簡(jiǎn)單:
<?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>
實(shí)現(xiàn)分?jǐn)郆utton,模仿MIUI設(shè)置頁(yè)面頂部Button
http://blog.csdn.net/hudan2714/article/details/8228173
自定義RadioButton樣式1
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元