开发者

Radio buttons: Replacing the stock round ones with built in android buttons

开发者 https://www.devze.com 2023-02-01 17:02 出处:网络
How do I create a group of radio buttons where the buttons look like nice stock android buttons? This is what I have found so far:

How do I create a group of radio buttons where the buttons look like nice stock android buttons?

This is what I have found so far:

The look of a radio button can be replaced with 4 drawables.There is an example of this on the web.


This does not work for me. So I have figured out two bad choices:

(A) Use stock buttons -do the radio logic in java. 开发者_StackOverflowGross.

(B) Render the buttons to drawables set them at runtime. Blah

Any ideas are very appreciated.

(This is my first question here. Hope it is well formulated.)


Use RadioButton and specify android:button="@drawable/mybutton", where res/drawable/mybuton.xml contains a custom <selector>:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:state_window_focused="false"
          android:drawable="@drawable/btn_radio_on" />
    <item android:state_checked="false" android:state_window_focused="false"
          android:drawable="@drawable/btn_radio_off" />

    <item android:state_checked="true" android:state_pressed="true"
          android:drawable="@drawable/btn_radio_on_pressed" />
    <item android:state_checked="false" android:state_pressed="true"
          android:drawable="@drawable/btn_radio_off_pressed" />

    <item android:state_checked="true" android:state_focused="true"
          android:drawable="@drawable/btn_radio_on_selected" />
    <item android:state_checked="false" android:state_focused="true"
          android:drawable="@drawable/btn_radio_off_selected" />

    <item android:state_checked="false" android:drawable="@drawable/btn_radio_off" />
    <item android:state_checked="true" android:drawable="@drawable/btn_radio_on" />
</selector>

This is actually the original selector for RadioButton.

0

精彩评论

暂无评论...
验证码 换一张
取 消