34

The checkbox border is invisible on white background.

enter image description here

I played with different color parameters without success. I need black border of box. Yes, there examples to make custom checkbox. In all drawable examples the normal box is visible inside of new shape. And the drawable shape is narrow without text in android:text="".

enter image description here

But why checkbox does not look okay in usual xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutBottom1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#FFFFFF"
    android:gravity="center" >
    <CheckBox
        android:id="@+id/checkBottom1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AAAA"
        android:visibility="visible"
        android:textColor="#000000"
        android:checked="true" />

</LinearLayout>

Any ideas? Thanks!

Nipun
  • 990
  • 1
  • 16
  • 25
Niaz
  • 545
  • 2
  • 12
  • 21

6 Answers6

77

You can use the property

android:buttonTint="what you want" to set your checkbox border color.

43

It's too late to answer but I would like to share what worked for me. Paste below code. It would change the CheckBox border color and textColor

styles.xml

<style name="MyCheckBox" parent="Theme.AppCompat.NoActionBar">
    <item name="colorControlNormal">#000</item>   <!-- normal border color change as you wish -->
    <item name="colorControlActivated">#000</item> <!-- activated color change as you wish -->
    <item name="android:textColor">#FFFF3F3C</item> <!-- checkbox text color -->
</style>

now in your main_activity.xml place below CheckBox code

<CheckBox android:id="@+id/check_agree"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:text="I agree"
          android:theme="@style/MyCheckBox"/>   <!-- here apply your checkbox style -->

if above style not working then replace parent theme parent="Theme.AppCompat.NoActionBar" with parent="Theme.AppCompat.Light". Hope it would work.

Ashfaque
  • 1,254
  • 1
  • 22
  • 38
5

Did you try going through here, here and here?
And as per answering your question

But why checkbox does not look okay in usual xml

Thats because sometimes, the android graphical view is not able to render the custom views, in that case you need to run the code on the emulator or the device to test it out.

UPDATE In case you dont want to use drawables, then you can also define the drawable shape in xml like

 <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >

        <solid android:color="#ffffff" >
        </solid>

        <stroke
            android:width="2dp"
            android:color="#ff0000" >
        </stroke>
<corners android:radius="5dp" />

    <padding
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp" />
    </shape>
Community
  • 1
  • 1
Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • 1
    In IntelliJ Idea's preview it looks okay. But not visible on Emulator and device. In your references they change check mark color. But I'd like to change box border color – Niaz Oct 19 '14 at 05:53
  • So you will need to have a slice for the box border. Slice as in an image which you would place in the drawable folder. – Antrromet Oct 19 '14 at 06:04
  • thanks, but not understood. What do you mean as a slice? – Niaz Oct 19 '14 at 06:07
  • _Slice as in an image which you would place in the drawable folder._ Anyway forget that, and check my updated answer. Also take a look at [this](http://stackoverflow.com/questions/20015463/defining-custom-checkbox-in-android). – Antrromet Oct 19 '14 at 06:09
  • I got text inside of text box trying your example. No. I need usual box with visible border. – Niaz Oct 19 '14 at 06:19
5

You can use either of them:

app:buttonTint="color code here"

or

android:buttonTint="color code here"
colidyre
  • 4,170
  • 12
  • 37
  • 53
Jwala Kumar
  • 525
  • 7
  • 9
2

None of the answers above worked for me, but this one did. It suggests using a selector and applying it to the checkbox, which worked perfectly for me.

This does not explain the odd look of the checkbox as shown above, which is why I wouldn't mark this question as a duplicate, but I think it still works as a solution.

Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46
0

For API level < 21 you can use :

app:buttonTint="EEEEEE"

For API level >= 21 you can use :

android:buttonTint="EEEEEE" 
guenter47
  • 457
  • 5
  • 13