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:
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:
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:
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"
/>
Setting the android:buttonTint="@color/mybrown" is an easy way to change the box color.
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.
So, the method to know if the check box is checked is : (CheckBox) yourCheckBox. isChecked() it returns true if the check box is checked.
You can call isChecked() on a checkbox to get its status.
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.
Just change the
android:buttonTint="YOUR COLOR"
It works.
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.
Add this attribute
android:buttonTint="#EEEEEE"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With