Android定制RadioButton樣式三種實現(xiàn)方法
更新時間:2013年02月21日 16:34:25 作者:
三種方法實現(xiàn)Android定制RadioButton樣式:使用XML文件進行定義/在JAVA代碼中定義等等,感興趣的朋友可以參考下,希望可以幫助到你
三種方法
1.使用XML文件進行定義 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前面的圓點
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前面的圓點adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定義,在JAVA代碼中使用 radioButton.setBackgroundResource(R.drawable.radio);調用
1.使用XML文件進行定義 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前面的圓點
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前面的圓點adioButton.setButtonDrawable(android.R.color.transparent);
3.使用XML文件定義,在JAVA代碼中使用 radioButton.setBackgroundResource(R.drawable.radio);調用
您可能感興趣的文章:
- Android單選按鈕RadioButton的使用詳解
- Android控件RadioButton實現(xiàn)多選一功能
- Android開發(fā)設置RadioButton點擊效果的方法
- Android編程實現(xiàn)自定義PopupMenu樣式示例【顯示圖標與設置RadioButton圖標】
- Android RadioButton 圖片位置與大小實例詳解
- Android RadioGroup和RadioButton控件簡單用法示例
- Android中設置RadioButton在文字右邊的方法實例
- android RadioButton和CheckBox組件的使用方法
- Android RadioButton單選框的使用方法
- Android控件系列之RadioButton與RadioGroup使用方法
- Android控件RadioButton的使用方法
相關文章
Android RecyclerView實現(xiàn)下拉列表功能
這篇文章主要介紹了Android RecyclerView實現(xiàn)下拉列表功能,下拉展開更多選項,具有一定的實用性,感興趣的小伙伴們可以參考一下2016-11-11
android中設置TextView/Button 走馬燈(Marquee)效果示例
定義走馬燈(Marquee),主要在Project/res/layout/main.xml即可,下面與大家分享下具體的實現(xiàn),感興趣的朋友可以參考下哈2013-06-06
android studio 3.6.1升級后如何處理 flutter問題
這篇文章主要介紹了android-studio-3.6.1升級后 flutter問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03

