0

I am trying to give the selector to the RadioButton of android:button but not able to showing that button in the preview as well as the real device, My goal is to make the android:button would be the custom. I have to RadioGroup with two RadioButton. I have tried this solution also https://stackoverflow.com/a/12432722/6869491 But still not able to get the desired solution.

<RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/padding_25"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="@id/sub_const"
            app:layout_constraintEnd_toEndOf="@id/sub_const"
            app:layout_constraintStart_toStartOf="@id/sub_const"
            app:layout_constraintTop_toBottomOf="@id/pay_amt_et">


            <RadioButton
                style="@style/MyRadioButtonStyle"
                android:id="@+id/manual_rb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:checked="true"
                android:text="@string/manual"
                android:textColor="@color/textcolor"
                android:textSize="@dimen/fontsize_16"
                />

            <RadioButton
                style="@style/MyRadioButtonStyle"
                android:id="@+id/recurring_rb"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Recuring"
                android:textColor="@color/textcolor"
                android:textSize="@dimen/fontsize_16"
             />
         </RadioGroup>

And here is the radio button selector, that is radio_btn_selector.

<item android:state_checked="true" android:state_window_focused="false"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_window_focused="false"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="true" android:state_pressed="true"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_pressed="true"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="true" android:state_focused="true"
    android:drawable="@drawable/radio_btn_active" />
<item android:state_checked="false" android:state_focused="true"
    android:drawable="@drawable/radio_btn_un_selected" />

<item android:state_checked="false" android:drawable="@drawable/radio_btn_un_selected" />
<item android:state_checked="true" android:drawable="@drawable/radio_btn_active" />

And here is the radio_btn_active.

 <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

        <item>

            <shape android:shape="oval">
                <solid android:color="@color/colorWhite" />

                <stroke
                    android:width="@dimen/padding_2"
                    android:color="@color/grey_darker" />

            </shape>
        </item>

        <item
            android:bottom="@dimen/padding_30"
            android:end="@dimen/padding_30"
            android:start="@dimen/padding_30"
            android:top="@dimen/padding_30">

            <shape android:shape="oval">
                <solid android:color="@color/primary_edtext_light" />


            </shape>
        </item>
    </layer-list>

And this is radio_btn_un_selected.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/colorWhite" />

    <stroke
        android:width="@dimen/padding_2"
        android:color="@color/grey_darker" />

</shape>

And Given the style as well.

<style name="MyRadioButtonStyle" 
     parent="@android:style/Widget.CompoundButton.RadioButton">
            <item name="android:button">@drawable/radio_btn_selector</item>
        </style>

Whats I am making wrong please guide me.

Amit Verma
  • 391
  • 2
  • 18
  • Possible duplicate of [RadioButton - how to use a custom drawable?](https://stackoverflow.com/questions/12432553/radiobutton-how-to-use-a-custom-drawable) – ADM Mar 06 '19 at 11:19
  • I have been tried that solution also but not able to get the solution – Amit Verma Mar 06 '19 at 11:49

1 Answers1

0

I think you missed to set RadioButton's android:background="@drawable/radio_btn_selector" property.

<RadioButton
            android:id="@+id/manual_rb"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="@string/manual"
            android:textColor="@color/textcolor"
            android:textSize="@dimen/fontsize_16"
            android:button="@android:color/transparent"
            android:background="@drawable/radio_btn_selector"
            />
Vishal G. Gohel
  • 1,008
  • 1
  • 16
  • 31
  • No its not the solution , it will take the whole background I have been tried for the only button background – Amit Verma Mar 06 '19 at 11:50