应用程序兼容性工具栏popupTheme不使用时多选择主动 [英] AppCompat ToolBar popupTheme not used when multi selection active

查看:455
本文介绍了应用程序兼容性工具栏popupTheme不使用时多选择主动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在styles.xml我造型工具栏中的溢出菜单的弹出式主题:

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.

任何想法我做错了吗?

工具栏的样式:

<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文件:

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:

推荐答案

菜单 - ActionMode 你看到你的默认 OptionsMenu 弹出背景是白色的,并为您的应用程序的默认上下文菜单是在您的案件黄河。当你进入到多选一ActionMode被触发来处理itemClick在和你有什么,因为你知道CAB是如何工作的。

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.

如果你想保持你的 setMultiChoiceModeListener 覆盖上prepareActionMode(ActionMode模式,菜单菜单)同样的白色背景 ,并使用 getCustomView()setBackgroundColor(Color.White);

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

修改寻址评论

这是我的意思是在你的上prePareActionMode()

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);
}

希望它有帮助

这篇关于应用程序兼容性工具栏popupTheme不使用时多选择主动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆