如何与我的主题指定暗操作模式 [英] How to specify dark action mode with my theme

查看:163
本文介绍了如何与我的主题指定暗操作模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有几个关于造型的上下文操作栏(ActionMode)的动作片吧的问题,但他们不太似乎并没有解决我后。

I know there are a couple of questions about styling the contextual action bar (ActionMode) piece of the action bar, but they don't quite seem to address what I'm after.

我使用的工具栏与光的主题和黑色的操作栏。工具栏看起来像我想的那样,但动作模式貌似正规黑暗的主题。我需要做什么在我的风格改变,以获得黑暗主题的动作模式(不只是行动起来吧)?看来我应该能够通过充分利用 Theme.AppCompat ,因为那表明我是多么希望它的CAB很快做到这一点,但我不希望应用程序的其它部分是黑暗。

I'm using the Toolbar with a light theme and dark action bar. The Toolbar looks like I want it, but the action mode looks like the regular dark theme. What do I need to change in my style to get the dark themed action mode (not just action bar)? It seems I should be able to do this quickly by tapping into Theme.AppCompat since that shows the CAB how I want it, but I don't want the rest of the application to be dark.

我只关心API 14+和现在用的支持工具栏代替行动吧。

I'm only concerned about API 14+ and am using the support Toolbar in place of action bar.

这是我的基本样式。

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:actionModeBackground">@color/colorActionMode</item>
    <item name="android:windowActionModeOverlay">true</item>
</style>

工具栏风格

<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
    <item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
    <item name="android:textColorSecondary">@color/abc_primary_text_material_dark</item>
    <item name="android:background">@color/colorPrimaryDark</item>
</style>

工具栏布局文件(这里设置popupTheme似乎并没有产生任何影响)。

Toolbar layout file (setting popupTheme here doesn't seem to have any effect).

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    app:theme="@style/AppTheme.Toolbar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
    android:elevation="2dp"
    android:focusable="false"/>

下面是我的工具栏(这是我想要的)

Here's my Toolbar (which is how I want it)

下面是我的ActionMode(我需要反转)

Here's my ActionMode (which I need to invert)

这就是我想要的ActionMode看,而不是 Theme.AppCompat喜欢(我得到了改变我的风格,从 Theme.AppCompat 继承.Light.DarkActionBar 。问题是,应用程序的其余部分会变暗,这是我不想要的。

Here's what I want the ActionMode to look like (which I got by changing my style to inherit from Theme.AppCompat instead of Theme.AppCompat.Light.DarkActionBar. The problem being that the rest of the application goes dark, which I don't want.

推荐答案

开始在你的基本主题压倒一切的属性 actionModeStyle

Start with overriding attribute actionModeStyle in your base theme:

<item name="actionModeStyle">@style/LStyled.ActionMode</item>

定义 LStyled.ActionMode 为:

<style name="LStyled.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
    <item name="titleTextStyle">@style/LStyled.ActionMode.Title</item>
    <item name="subtitleTextStyle">@style/LStyled.ActionMode.Subtitle</item>
</style>

最后:

<style name="LStyled.ActionMode.Title" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
    <item name="android:textColor">@color/color_action_mode_text</item>
</style>

<style name="LStyled.ActionMode.Subtitle" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle">
    <item name="android:textColor">@color/color_action_mode_text</item>
</style>

这将覆盖指定主题文字颜色(S)为标题和放大器;字幕(如果需要的话)。

This will override theme specified text color(s) for title & subtitle(if needed).

剩下的就是溢出按钮。火了一个支持彩色替换任何图像编辑软件。使用溢出菜单从AppCompat的 RES /绘制-XXXX 文件夹PNG。涂料是白色的。接下来,覆盖 actionOverflowButtonStyle 在你的基本主题,并指定你刚刚修改为PNG:

What's left is the overflow button. Fire up any image editing software that supports color-replacement. Use the overflow menu png from AppCompat's res/drawable-XXXX folder. Paint it white. Next, override actionOverflowButtonStyle in your base theme and specify the png you've just modified:

<item name="actionOverflowButtonStyle">@style/LStyled.OverFlow</item>

<style name="LStyled.OverFlow" parent="@style/Widget.AppCompat.ActionButton.Overflow">
    <item name="android:src">@drawable/modified_overflow_icon</item>
</style>

没有太多的解释/教程,我可以提供关于主题定制。只有这样,才能获得挂起它是从框架通过[风格] [主题] .xml文件。阅读源$ C ​​$ C也有助于 - 你会得到知道什么属性正在被使用,其中,/如果他们可以定制。

There's not much of an explanation/tutorial that I can provide regarding customization of themes. The only way to get a hang of it is to go through [styles][themes].xml files from the framework. Reading the source code also helps - you'll get to know what attributes are being used and where/if they can be customized.

提点:

我希望能够扩展样式以获得相同的行为,这是   内置在黑暗的主题。

I want to be able to extend a style to get the same behavior that's built into the dark theme.

是的,但是这可能不是期望的。以上的部分将讨论修改溢出菜单图标可以被覆盖 colorControlNormal 属性所取代。 TintManager (<一href="http://androidxref.com/5.0.0_r2/xref/frameworks/support/v7/appcompat/src/android/support/v7/internal/widget/TintManager.java"相对=nofollow>链接)使用从 colorControlNormal 来着色溢出菜单绘制(其它可绘制之间)。看看数组的内容 TINT_COLOR_CONTROL_NORMAL 源$ C ​​$ C。但是覆盖 colorControlNormal 来修复一个绘制可能改变整体外观和放大器;觉得该应用程序的更糟糕。

Yes, but this might not be desired. The part above that deals with modifying overflow menu icon can be substituted with an overridden colorControlNormal attribute. TintManager (Link) uses the color value from colorControlNormal to tint the overflow menu drawable (among other drawables). Take a look at the contents of array TINT_COLOR_CONTROL_NORMAL in the source code. But overriding colorControlNormal to fix one drawable may change the overall look & feel of the app for worse.

这篇关于如何与我的主题指定暗操作模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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