Dennis Lu
Dennis Lu

Reputation: 802

How to change theme for checkbox in toolbar

I use Toolbar and Menu in my class.

Here is the menu_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<group android:checkableBehavior="all">
    <item
        android:id="@+id/menu_main_checkbox"
        android:title="checkbox"
        app:actionViewClass="android.support.v7.widget.AppCompatCheckBox"
        app:showAsAction="ifRoom" />
</group>

<item
    android:id="@+id/menu_main_delete"
    android:title="@string/menu_main_delete"
    app:showAsAction="never" />

<item
    android:id="@+id/menu_main_rename"
    android:title="@string/menu_main_rename"
    app:showAsAction="never" />

<item
    android:id="@+id/menu_main_copy"
    android:title="@string/menu_main_copy"
    app:showAsAction="never" />

<item
    android:id="@+id/menu_main_new_folder"
    android:title="@string/menu_main_new_folder"
    app:showAsAction="never" />

And here is what it is now:

enter image description here enter image description here

How should i do to change the theme for checkbox in toolbar? I hope it can be white when checked.

Upvotes: 1

Views: 200

Answers (1)

Rahul Khurana
Rahul Khurana

Reputation: 8844

You can change checkbox color directly in the xml. Use buttonTint value for the box: (as of API level 23)

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:buttonTint="@color/CHECK_COLOR" />

You can also do this using appCompatCheckbox v7 for older APIs:

<android.support.v7.widget.AppCompatCheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:buttonTint="@color/COLOR_HERE" /> 

Upvotes: 2

Related Questions