Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of a radio button

Tags:

android

I am developing an quiz based app. There will be 1 question and 4 option(radio buttons). If user select any wrong answer then I want to turn that radio button color to Red. How to do this?

like image 280
shiv Avatar asked Sep 09 '13 10:09

shiv


People also ask

How do I change the color of the radio button in Chrome?

You can use the CSS accent-color property to change the colour. It works with Chrome/Edge 93+, Firefox 92+, and Safari 15.4+ (Browser support info from caniuse.)

How do I change the color of my disabled radio button?

An easy way to change the style of a disabled radio button is a simple absolute positioned overlay with the :after attribute. You can adjust the background color and borders as you see fit. Show activity on this post. Try adding the border colour as i believe thats the initial edge styling.

How do I change the color of a radio button in Wordpress?

Go to Edit Form → Settings → Style → Global, and at the Theme colors options you can choose the theme colors.


1 Answers

Just came to show something that really help me with this:

Everyone talks about how to use the tint and how to use the colorAccent, but, this wont work on phones with API less than 21.

So, the real fix on this or at least what helped me was to use android.support.v7.widget.AppCompatRadioButton instead of RadioButton

With this on your layout, you can use: app:buttonTint="@color/yourColor"

without getting warnings or problems about the compat of the view.

And, don't you forget about adding:

xmlns:app="http://schemas.android.com/apk/res-auto"

to your layout parent or to your widget.

Edit:

@aselims mention on a comment that there's not buttonTintin the app namespace.

So... here's my current style for this solution:

<style name="MRadioButton.Purple" parent="Widget.AppCompat.CompoundButton.RadioButton">
    <item name="colorAccent">@color/youColor</item>
    <item name="colorControlHighlight">@color/yourColor</item>
    <item name="android:colorPressedHighlight">@color/yourColor</item>
    <item name="colorPrimaryDark">@color/yourColor</item>
    <item name="colorPrimary">@color/yourColor</item>
    <item name="colorControlActivated">@color/yourColor</item>
</style>
like image 186
Sierisimo Avatar answered Sep 27 '22 19:09

Sierisimo