I have a RadioGroup
with two RadioButtons. I want to change the color of them programmatically when they are disabled.
<RadioGroup
android:id="@+id/radio_group_transfer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:layoutDirection="ltr"
android:orientation="horizontal">
<RadioButton
android:id="@+id/national_id_docs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/radio_btn_selector_left"
android:button="@null"
android:checked="true"
android:gravity="center"
android:padding="10dp"
android:text="@string/national_id"
android:textColor="@drawable/radio_btn_textcolor_selector"
style="@style/SimpleTextStyleSemiBold"/>
<RadioButton
android:id="@+id/passport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/radio_btn_selector_right"
android:button="@null"
android:gravity="center"
android:padding="10dp"
android:text="@string/passport"
android:textColor="@drawable/radio_btn_textcolor_selector"
style="@style/SimpleTextStyleSemiBold"/>
</RadioGroup>
I have created new XML selectors with gray colors but when I set the background it does not work.
radio_btn_selector_left_disabled.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<solid android:color="@color/employee_non_editable_color_grey" />
<stroke android:width="1dp" android:color="@color/employee_non_editable_color_grey" />
<corners android:bottomLeftRadius="3dp" android:topLeftRadius="3dp"/>
</shape>
</item>
<item android:state_checked="false">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="@color/employee_non_editable_color_grey" />
<corners android:bottomLeftRadius="3dp" android:topLeftRadius="3dp"/>
</shape>
</item>
</selector>
I tried
national_id_docs.setBackground(R.drawable.radio_btn_selector_left_disabled);
could you suggest what is the best way to use the radio_btn_selector_left_disabled
for the radio button?
To get your selected radio button value
Solution 1: Change colorAccent color
Solution 2: Create your style in your style.xml and extend it to your radio button.
Solution 3: Use AppCompatRadioButton