操作栏标题/图标不使用主题颜色 [英] Action bar title/icon not using theme color

查看:91
本文介绍了操作栏标题/图标不使用主题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了我的应用程序的操作栏自定义样式。我已经改变了操作栏的蓝色背景和白色的文字,我想,这工作正常。然而围绕着应用程序的标题和图标,我认为这是透明的地区,该地区正显示出总的主题背景,而不是操作栏背景。因此,而不是透明度通过降的动作吧,它的下跌通过对基础背景。

下面是一个显示问题的图像(我已经改变了主题背景为红色来突出问题)。

我怎样才能解决这个问题?

下面是我的styles.xml文件:

<资源>    <样式名称=MyTheme的父=@风格/ Theme.AppCompat>
        <项目名称=机器人:背景>#FF0000< /项目>
        <项目名称=机器人:文字颜色> @彩色/ cp_text< /项目>
        <项目名称=机器人:actionBarStyle> @风格/ CustomActionBar< /项目>
        <项目名称=机器人:actionButtonStyle> @风格/ CustomActionBarButton< /项目>
        <项目名称=机器人:actionModeBackground> @彩色/ cp_titlebar_background< /项目>
    < /风格>    <样式名称=CustomActionBar父=@风格/ Widget.AppCompat.ActionBar>
        <项目名称=机器人:背景> @彩色/ cp_titlebar_background< /项目>
        <项目名称=机器人:文字颜色> @彩色/ cp_text< /项目>
        <项目名称=机器人:titleTextStyle> @风格/ CPTitleTextStyle< /项目>
    < /风格>    <样式名称=CPTitleTextStyle父=@风格/ TextAppearance.AppCompat.Widget.ActionBar.Title>
        <项目名称=机器人:文字颜色> @彩色/ cp_text< /项目>
        <项目名称=机器人:背景> @彩色/ cp_titlebar_background< /项目>
    < /风格>    <样式名称=CustomActionBarButton父=@安卓风格/ Widget.ActionButton>
        <项目名称=机器人:背景> @彩色/ cp_titlebar_background< /项目>
    < /风格>< /资源>


解决方案

通过设置<项目名称=机器人:背景>#FF0000< /项目> 你的基本主题,所有的意见和窗口小部件将使用该值对他们的背景。

如果你想要设置你的主题活动背景颜色,然后使用android:windowBackground属性而不是背景

I'm doing a custom style for the action bar in my application. I've changed action bar to the blue background and white text that I wanted, and that works fine. However the area around the app's title and icon, which I think is the transparent region, is showing the general theme background instead of the action bar background. So instead of the transparency 'falling through' to the action bar, it's falling through to the base background.

Here's an image that displays the problem (I've changed the theme background to red to highlight the issue).

How can I resolve this?

Here's my styles.xml file:

<resources>

    <style name="MyTheme" parent="@style/Theme.AppCompat">
        <item name="android:background">#FF0000</item>
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:actionBarStyle">@style/CustomActionBar</item>
        <item name="android:actionButtonStyle">@style/CustomActionBarButton</item>
        <item name="android:actionModeBackground">@color/cp_titlebar_background</item>
    </style>

    <style name="CustomActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:background">@color/cp_titlebar_background</item>
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:titleTextStyle">@style/CPTitleTextStyle</item>
    </style>

    <style name="CPTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:background">@color/cp_titlebar_background</item>
    </style>

    <style name="CustomActionBarButton" parent="@android:style/Widget.ActionButton">
        <item name="android:background">@color/cp_titlebar_background</item>
    </style>

</resources>

解决方案

By setting <item name="android:background">#FF0000</item> on your base theme, all views and widgets will use this value for their background.

If you are wanting to set the background colour for activities in your theme, then use the android:windowBackground attribute instead of background.

这篇关于操作栏标题/图标不使用主题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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