試試這個,
你activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/style_toggle_button" />
</RelativeLayout>
風格切換按鈕(style_toggle_button.xml):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/offcirclebutton" android:state_enabled="false"/>
<item android:drawable="@drawable/oncirclebutton" android:state_pressed="true"/>
<item android:drawable="@drawable/oncirclebutton" android:state_checked="true"/>
<item android:drawable="@drawable/oncirclebutton" android:state_focused="true"/>
<item android:drawable="@drawable/offcirclebutton"/>
</selector>
樣式OFF(offcirclebutton.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true">
<solid android:color="@android:color/holo_orange_dark" />
</shape>
風格ON(oncirclebutton.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true">
<solid android:color="@android:color/holo_green_dark" />
</shape>
你能嘗試只是把一個顏色? – 2014-11-21 15:52:04
我做了,它顯示的顏色,由於某種原因,它甚至顯示在Android工作室的圓形按鈕,但在我的手機上它不 – user3553551 2014-11-21 16:28:04