Skip to content Skip to sidebar Skip to footer

Change Background For Radio Button Programatically

I have a RadioGroup with two RadioButtons. I want to change the color of them programmatically when they are disabled. Copy

Solution 2:

To get your selected radio button value

finalRadioGroupradioSpam= (RadioGroup) findViewById(R.id.radio_group_transfer);
            RadioButton radioButton;
            intselectedId= radioSpam.getCheckedRadioButtonId();

Solution 1: Change colorAccent color

< color name="colorAccent">#75aeff</color >

Solution 2: Create your style in your style.xml and extend it to your radio button.

<stylename="MyRadioButton"parent="Theme.AppCompat.Light"><itemname="colorControlNormal">@color/indigo</item><itemname="colorControlActivated">@color/pink</item></style><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true"android:text="Radio Button"android:theme="@style/MyRadioButton"/>

Solution 3: Use AppCompatRadioButton

 <android.support.v7.widget.AppCompatRadioButton
        android:id="@+id/rbtn_test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:buttonTint="@color/primary" />

Post a Comment for "Change Background For Radio Button Programatically"