Reputation: 303
How do I change the color of an unchecked menu item in a toolbar's submenu?
I know that the checked state is defined by the accentColor
of the corresponding theme. But I couldn't find a way to define a color for the unchecked state.
Just to be clear: I can't define a toolbar's menu item using a custom layout XML and I do not have direct access to the view object and the checkbox.
A menu like this is defined like so:
<menu>
<item
android:id="@+id/sortByDescriptionDescendingAction_mediumDark"
android:icon="@drawable/ic_sort_white_24dp"
android:title="@string/sortByDescriptionDescendingAction"
android:checkable="true"/>
<item
android:id="@+id/sortByDescriptionAscendingAction_mediumDark"
android:icon="@drawable/ic_sort_white_24dp"
android:title="@string/sortByDescriptionAscendingAction"
android:checkable="true"/>
<item
android:id="@+id/sortByDateDescendingAction_mediumDark"
android:icon="@drawable/ic_sort_white_24dp"
android:title="@string/sortByDateDescendingAction"
android:checkable="true"
android:checked="true"/>
<item
android:id="@+id/sortByDateDescAction_mediumDark"
android:icon="@drawable/ic_sort_white_24dp"
android:title="@string/sortByDateAscendingAction"
android:checkable="true"/>
</menu>
Upvotes: 5
Views: 2612
Reputation: 23881
Try using R.attr of android: see this
in your values/styles.xml:
Define custom style for toolbar
:
<style name="CustomPopupTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:colorControlActivated">@color/BLUE</item>
<item name="android:colorControlHighlight">@color/BLUE</item>
<item name="android:colorControlNormal">@color/white</item>
</style>
Apply it using:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/CustomPopupTheme" />
Upvotes: 7