0

I want to apply custom check box design. I followed this post How to apply custom image to checkbox in android, but unfortunately it didn't work for me (in preview screen and also on physical device, I see gray square, which becomes lighter gray on checking). Here is my code:

File where I am applying custom checkbox design (see CheckBox definition) category_spinner_dropdown_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/categorySpinnerDropdownItemCheckBox"
            android:layout_width="35dp"
            android:layout_height="20dp"
            android:button="@drawable/custom_checkbox_selector"
            android:background="@android:color/transparent"/>

        <TextView
            android:id="@+id/categorySpinnerDropdownItemTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textAppearance="@style/toolbar_text_white"/>

    </LinearLayout>

    <Space
        android:layout_width="match_parent"
        android:layout_height="7dp"/>

</LinearLayout>

Here is definition of selector: custom_check_box_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/custom_checkbox"
            android:state_checked="false"/>
        <item android:drawable="@drawable/custom_checkbox_checked"
            android:state_checked="true"/>
        <item android:drawable="@drawable/custom_checkbox"/>
</selector>

Here are custom_checkbox and custom_checkbox_checked enter image description here enter image description here

What am I doing wrong? Thanks!

Darian Pudic
  • 45
  • 2
  • 10

1 Answers1

0

Solution that works for me is usage of

<androidx.appcompat.widget.AppCompatCheckBox

instead of regular CheckBox. I left everything else unchanged.

Darian Pudic
  • 45
  • 2
  • 10