AppCompat ToolBar popupTheme not used when multi s

2019-06-05 04:22发布

In styles.xml I'm styling the popup theme of the overflow menu in the toolbar:

<style name="ToolbarOverflowMenuStyle" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:backgroundTint">@color/white</item>
</style>

That works as intended but if I do a multi selection in a recycler view (list) the popup theme background color turns from white to yellow (the color of the toolbar). I have no idea why that is since it has the right color if the multi-selection isn't active.

Any ideas what I am doing wrong?

Styling of the toolbar:

<style name="PostToolbarStyle" parent="android:Theme.Material">
    <item name="android:backgroundTint">@color/yellow</item>
    <item name="android:textColorHint">@color/lightGray2</item>
    <item name="android:textColorPrimary">@color/defaultTextColor</item>
    <item name="android:textColorSecondary">@color/defaultTextColor</item>
</style>

And this is how I set the toolbar in the layout xml file:

<android.support.v7.widget.Toolbar
    android:id="@+id/app_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:minHeight="?attr/actionBarSize"
    android:paddingTop="@dimen/tool_bar_top_padding"
    app:popupTheme="@style/ToolbarOverflowMenuStyle"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>

How the popup theme looks like (correctly) when multi-selection is not active: Displayed correctly

And here how is being displayed (wrongly) when multi-select is active: enter image description here

2条回答
萌系小妹纸
2楼-- · 2019-06-05 05:04

Can you Try editing you style with this property, selectableItemBackground

  <style name="ToolbarOverflowMenuStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:backgroundTint">@color/white</item>
<item name="selectableItemBackground">?android:selectableItemBackground</item></style>

Had a similar problem with SwitchCompat and the solution was in one of the properties itself. Also this blog helped a lot . http://blog.mohitkanwal.com/blog/2015/03/07/styling-material-toolbar-in-android/

查看更多
Explosion°爆炸
3楼-- · 2019-06-05 05:12

Its Menu -ActionMode you see your default OptionsMenu popUp background is the white, and the default contextual Menu for your app is the Yellow in your case. When you enter into multi-selection a ActionMode is triggered to handle the itemClick and what have you, and since you know how CAB works.

if you want to maintain the same white background in your setMultiChoiceModeListener override onPrepareActionMode(ActionMode mode, Menu menu) and use getCustomView().setBackgroundColor(Color.White);

Edit: addressing comment

This is what i mean in your onPrePareActionMode()

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    //the mode parameter is your CAB, so call that on it
    mode.getCustomView().setBackgroundColor(Color.White);
}

Hope its helpful

查看更多
登录 后发表回答