Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5.0 makes unselected checkboxes invisible when background is white

I have an android app that has been working fine pre-Android 5.0. With the update, I noticed that checkboxes and radiobuttons placed on white backgrounds are not visible if they are not selected. For example, this is what a checkbox looks selected and unselected in jellybean:

enter image description hereenter image description here

As you can see, there is a light gray square when the checkbox is not selected. However, after updating to lollipop, this is what it looks like:

enter image description hereenter image description here

So, as you can see, there is no gray square or anything that suggests there is a checkbox here. The same problem happens with radiobuttons. I really don't want to go trough the pain of creating new drawables just for this simple ting. I have seen that checkboxes within the accessibility menu of android 5 have a nice square, but haven't figured out how to make mine look the same:

enter image description here

I tried creating a new android project and just adding some checkboxes and radio buttons with a white background, but they are still invisible when unchecked. I'm using xamarin studio and c#, if that makes any difference. Anyway, I'll understand any java code you post.

This is what my checkbox code looks like:

          <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:id="@+id/chkSeleccionar"
            android:layout_gravity="right"
            android:gravity="center_vertical"
            android:clickable="false"
            android:focusable="false"
            android:scaleX="1.5"
            android:scaleY="1.3"
            android:layout_weight="50"
          />
like image 627
Alex Terreaux Avatar asked Nov 28 '14 20:11

Alex Terreaux


People also ask

How do you change the color of a check box?

Setting the android:buttonTint="@color/mybrown" is an easy way to change the box color.

How can change fill color of checkbox in Android?

This example demonstrates how do I change the color of the check box in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you know checkbox is checked or not in android?

So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.

What is the way to get the checked status of checkbox in Android?

You can call isChecked() on a checkbox to get its status.


4 Answers

I couldn't get the theme working, but what did work for me was the following:

android:button="@drawable/abc_btn_check_material"
android:buttonTint="@color/red"

Put this into your CheckBox XML layout.

like image 69
0xMatthewGroves Avatar answered Oct 25 '22 17:10

0xMatthewGroves


Just change the

android:buttonTint="YOUR COLOR"

It works.

like image 20
jsam Avatar answered Oct 25 '22 17:10

jsam


Make sure you are using a Material theme for Android 5.0 devices - this will ensure you're styling remains consistent with other components. Look for an android:theme element in your AndroidManifest.xml file (either on your application or on an individual activity), then look up what style is set there and check the parent attribute for the style.

like image 30
ianhanniballake Avatar answered Oct 25 '22 17:10

ianhanniballake


Add this attribute

android:buttonTint="#EEEEEE"
like image 33
code cry Avatar answered Oct 25 '22 18:10

code cry