AppCompat ToolBar popupTheme not used when multi selection active

老子叫甜甜 提交于 2019-12-08 04:28:14

问题


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:

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


回答1:


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




回答2:


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/



来源:https://stackoverflow.com/questions/30526667/appcompat-toolbar-popuptheme-not-used-when-multi-selection-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!