多选活动时不使用 AppCompat ToolBar popupTheme

AppCompat ToolBar popupTheme not used when multi selection active

在 styles.xml 中,我正在设计工具栏中溢出菜单的弹出主题:

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

按预期工作,但如果我在回收器视图(列表)中执行多 selection,弹出主题背景颜色会从白色变为黄色(工具栏的颜色)。我不知道为什么会这样,因为如果 multi-selection 未激活,它具有正确的颜色。

知道我做错了什么吗?

工具栏的样式:

<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>

这就是我在布局 xml 文件中设置工具栏的方式:

<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"/>

当 multi-selection 未激活时弹出主题的外观(正确):

当 multi-select 处于活动状态时,这里是如何(错误地)显示的:

你能试试用这个 属性、selectableItemBackground

来编辑你的样式吗
  <style name="ToolbarOverflowMenuStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:backgroundTint">@color/white</item>
<item name="selectableItemBackground">?android:selectableItemBackground</item></style>

与 SwitchCompat 有类似的问题,解决方案是在其中一个属性中。此博客也有很大帮助。 http://blog.mohitkanwal.com/blog/2015/03/07/styling-material-toolbar-in-android/

它的 Menu -ActionMode 你会看到你的默认 OptionsMenu 弹出窗口背景是白色的,你的应用程序的默认上下文菜单是黄色的。当您进入多选时,将触发 ActionMode 来处理 itemClick 和您有什么,因为您知道 CAB 是如何工作的。

如果您想在 setMultiChoiceModeListener 中保持相同的白色背景,请覆盖 onPrepareActionMode(ActionMode mode, Menu menu) 并使用 getCustomView().setBackgroundColor(Color.White);

编辑处理评论

这就是我在你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);
}

希望对您有所帮助