Android定制RadioButton樣式三種實(shí)現(xiàn)方法
更新時(shí)間:2013年02月21日 16:34:25 作者:
三種方法實(shí)現(xiàn)Android定制RadioButton樣式:使用XML文件進(jìn)行定義/在JAVA代碼中定義等等,感興趣的朋友可以參考下,希望可以幫助到你
三種方法
1.使用XML文件進(jìn)行定義 res/drawable/radio.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 未選中->
<item
android:state_checked="false"
android:drawable="@drawable/tabswitcher_long" />
<!--選中->
<item
android:state_checked="true"
android:drawable="@drawable/tabswitcher_short" />
</selector>
在布局文件中使用
<RadioGroup
...
>
<RadioButton
...
android:button="@null"
android:background="@drawable/radio"
/>
</RadioGroup>
ndroid:button="@null" 去除RadioButton前面的圓點(diǎn)
android:background="@drawable/radio" 使用定義的樣式
2.在JAVA代碼中定義
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
this.setBackgroundResource(com.wxg.tab.R.drawable.main_bg);
}else if(event.getActionMasked()== MotionEvent.ACTION_DOWN) {
this.setBackgroundResource(com.wxg.tab.R.drawable.hui);
}
return super.onTouchEvent(event);
}
去除RadioButton前面的圓點(diǎn)adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定義,在JAVA代碼中使用 radioButton.setBackgroundResource(R.drawable.radio);調(diào)用
1.使用XML文件進(jìn)行定義 res/drawable/radio.xml
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 未選中->
<item
android:state_checked="false"
android:drawable="@drawable/tabswitcher_long" />
<!--選中->
<item
android:state_checked="true"
android:drawable="@drawable/tabswitcher_short" />
</selector>
在布局文件中使用
復(fù)制代碼 代碼如下:
<RadioGroup
...
>
<RadioButton
...
android:button="@null"
android:background="@drawable/radio"
/>
</RadioGroup>
ndroid:button="@null" 去除RadioButton前面的圓點(diǎn)
android:background="@drawable/radio" 使用定義的樣式
2.在JAVA代碼中定義
復(fù)制代碼 代碼如下:
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
this.setBackgroundResource(com.wxg.tab.R.drawable.main_bg);
}else if(event.getActionMasked()== MotionEvent.ACTION_DOWN) {
this.setBackgroundResource(com.wxg.tab.R.drawable.hui);
}
return super.onTouchEvent(event);
}
去除RadioButton前面的圓點(diǎn)adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定義,在JAVA代碼中使用 radioButton.setBackgroundResource(R.drawable.radio);調(diào)用
您可能感興趣的文章:
- Android單選按鈕RadioButton的使用詳解
- Android控件RadioButton實(shí)現(xiàn)多選一功能
- Android開(kāi)發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法
- Android編程實(shí)現(xiàn)自定義PopupMenu樣式示例【顯示圖標(biāo)與設(shè)置RadioButton圖標(biāo)】
- Android RadioButton 圖片位置與大小實(shí)例詳解
- Android RadioGroup和RadioButton控件簡(jiǎn)單用法示例
- Android中設(shè)置RadioButton在文字右邊的方法實(shí)例
- android RadioButton和CheckBox組件的使用方法
- Android RadioButton單選框的使用方法
- Android控件系列之RadioButton與RadioGroup使用方法
- Android控件RadioButton的使用方法
相關(guān)文章
Android 啟動(dòng)第三方程序的方法總結(jié)
這篇文章主要介紹了Android 啟動(dòng)第三方程序的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-04-04
Android實(shí)現(xiàn)滑動(dòng)標(biāo)簽頁(yè)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)滑動(dòng)標(biāo)簽頁(yè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-04-04
Android多點(diǎn)觸控實(shí)現(xiàn)圖片自由縮放
這篇文章主要為大家詳細(xì)介紹了Android多點(diǎn)觸控實(shí)現(xiàn)圖片自由縮放,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
Android RecyclerView實(shí)現(xiàn)下拉列表功能
這篇文章主要介紹了Android RecyclerView實(shí)現(xiàn)下拉列表功能,下拉展開(kāi)更多選項(xiàng),具有一定的實(shí)用性,感興趣的小伙伴們可以參考一下2016-11-11
android中設(shè)置TextView/Button 走馬燈(Marquee)效果示例
定義走馬燈(Marquee),主要在Project/res/layout/main.xml即可,下面與大家分享下具體的實(shí)現(xiàn),感興趣的朋友可以參考下哈2013-06-06
android studio 3.6.1升級(jí)后如何處理 flutter問(wèn)題
這篇文章主要介紹了android-studio-3.6.1升級(jí)后 flutter問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android自定義View實(shí)現(xiàn)雪花特效
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)雪花特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-02-02

