Android radiobutton background style when selected

后端 未结 3 2002
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 16:32

I know how to set background for my radio button. But I don\'t know what is the best/right way to change background of selected radio button? Is it possible to make it in xm

相关标签:
3条回答
  • 2021-01-01 16:49

    You can define a selector for your radio button as described in this answer:

    Is it possible to change the radio button icon in an android radio button group

    0 讨论(0)
  • 2021-01-01 17:02

    Just create a selector xml file in drawable folder

    checkbox_background.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
          <item android:state_checked="true" android:drawable="@color/checkbox_active" />
          <item android:state_checked="false" android:drawable="@color/checkbox_inactive" />
    </selector>
    

    And apply this background to your radio buttons

     <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/checkbox_background" />
    
    0 讨论(0)
  • 2021-01-01 17:06

    Use

    android:gravity="center"
    

    for the radio button. This will center the text.

    0 讨论(0)
提交回复
热议问题