欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

自定義RadioButton&CheckBox樣式的實現

系統 2300 0
http://hi.baidu.com/ljlkings/blog/item/a7945124de875c038a82a1b4.html

Android 自定義RadioButton的樣式

我們知道Android控件里的button,listview可以用xml的樣式自定義成自己希望的漂亮樣式。
  最近用到RadioButton,利用xml修改android:background="@drawable/button_drawable",其中button_drawable為自己定義的.xml文件(res/drawable文件下),但是不成功,到網上查找,也沒有正確的說法,我就開始自己嘗試,最后做好了。
  其實方法很簡單,同樣在res/drawable新建radiobutton.xml如下
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item
            android:state_enabled="true"
             android:state_checked="true"
            android:drawable="@drawable/check" />
       <item
             android:state_enabled="true"
             android:state_checked="false"
             android:drawable="@drawable/checknull" />
   </selector>
  

  1 check和checknull分別為選中和位選中的圖片。
  1 然后在你的布局文件中,RadioButton 布局
  1 設置android:button = "@drawable/radiobutton",就可以了!
  前后圖片對比如下:

自定義RadioButton&CheckBox樣式的實現


RadioButton修改樣式
    
<?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> 

  

    
<?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> 


  


Android 自定義CheckBox 樣式
http://www.pocketdigi.com/20110623/347.html
1,新建Android XML文件,類型選Drawable,根結點選selector,在這定義具體的樣式。
    
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:state_checked="true" android:state_pressed="true"
		android:drawable="@drawable/focused" />
	<item android:state_checked="false" android:state_pressed="true"
		android:drawable="@drawable/normal" />
	<item android:state_checked="false" android:drawable="@drawable/normal" />
	<item android:state_checked="true" android:drawable="@drawable/focused" />
</selector>

  

2,應用到Checkbox與Button不同,并不是設置Background屬性,而是設置style屬性,所以我們要寫一個style。
在style.xml寫一個style,
    <style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox</item>
</style>
  

3,應用到Checkbox:
    
<CheckBox android:layout_width="wrap_content" 
android:layout_height="wrap_content"
style="@style/MyCheckBox"
/>

  



新浪搜索界面 用到 自定義RadioButton
http://www.eoeandroid.com/thread-53703-1-1.html

風格化的 Toggle Buttons
http://blog.csdn.net/billpig/article/details/6634481

事實上,可以使用ToggleButton來模仿CheckBox:
    
<ToggleButton android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_toggle"/>

  

bg_toggle.xml:
    
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/toggle_me_on" /> 
    <item android:drawable="@drawable/toggle_me_off" />
</selector>

  


讓CheckBox的選擇框顯示在右邊



只要注意android:button和android:drawableRight就行了:
    
<style name="style_checkbox">
        <item name="android:layout_width">wrap_content</item>
		<item name="android:layout_height">wrap_content</item>
		<item name="android:paddingRight">25dp</item>
		<item name="android:paddingTop">5dp</item>
		<item name="android:paddingBottom">5dp</item>
		<item name="android:textColor">@color/white</item>
		<item name="android:textSize">@dimen/font_middle</item>
		<item name="android:textStyle">italic</item>
		<item name="android:singleLine">true</item>
		<item name="android:button">@null</item>
		<item name="android:drawableRight">@drawable/mycheckbox</item>
		<item name="android:drawablePadding">5dp</item>
		<item name="android:background">@android:color/transparent</item>
    </style>

  



自定義RadioButton&CheckBox樣式的實現

自定義RadioButton&CheckBox樣式的實現


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久综合狠狠综合久久 | 久久草在线精品 | 国产精品视频网站 | 99热这里只有免费国产精品 | 久久中文字幕不卡一二区 | 国产成人综合一区精品 | 成人在线免费视频播放 | 国产a做爰全过程片 | 亚洲精品国产一区 | 日韩有码在线观看 | www.av视频 | 四虎1515hh永久久免费 | 91久久久久久久久久久 | 99热久久这里只精品国产 | 在线高清免费观看视频 | 九九在线视频 | 午夜啪视频 | 国产99久久精品一区二区永久免费 | 久久久久国产一区二区三区四区 | 操操操日日日干干干 | 成人欧美一区二区三区在线观看 | 美女伊人| 久久天堂av | 9久热这里只有精品视频在线观看 | 免费看的毛片 | 56av国产精品久久久久久久 | 全黄一级裸片视频免费 | 亚洲午夜精品一区二区三区他趣 | 色欲AV久久一区二区三区 | 色哦色哦哦色天天综合 | 国产欧美日韩精品a在线观看高清 | 日韩在线免费电影 | 九色网址 | 日本一在线中文字幕天堂 | 国产精品久久久久无码AV1 | 国产一区二区自拍 | 天天视频国产 | 国产综合一区二区 | 手机在线一区二区三区 | 超级在线牛碰碰视频 | 亚洲www啪成人一区二区麻豆 |