日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

自定義RadioButton樣式1

系統 1774 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>

  


上面的寫法有點拖沓,采用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> 

  


實現分斷Button,模仿MIUI設置頁面頂部Button
http://blog.csdn.net/hudan2714/article/details/8228173

自定義RadioButton樣式1


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 道孚县| 石家庄市| 阳谷县| 济南市| 巴林左旗| 丹阳市| 东宁县| 木里| 自治县| 门源| 河源市| 石城县| 西藏| 六安市| 马尔康县| 呼和浩特市| 贵州省| 长白| 平阳县| 郧西县| 香格里拉县| 广灵县| 嘉兴市| 萝北县| 通河县| 西丰县| 高唐县| 友谊县| 天祝| 青海省| 永靖县| 萨嘎县| 玛曲县| 衡南县| 武夷山市| 萍乡市| 石家庄市| 稻城县| 固阳县| 太原市| 怀宁县|