在 android 上更改 AppCompat Light DarkActionBar 主题的背景和文本颜色 [英] Changing Background and text color of AppCompat Light DarkActionBar Theme on android

查看:34
本文介绍了在 android 上更改 AppCompat Light DarkActionBar 主题的背景和文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用了 AppCompat Light DarkActionBar 主题.

I have used AppCompat Light DarkActionBar Theme for my App.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        
</style>

是否可以更改此 ActionBar 的背景颜色和文本颜色?如果是,如何?

Is it possible to change the background color and text color of this ActionBar ? If yes, how ?

推荐答案

以下代码将允许您完全设置操作栏的样式.

The following code will allow you to completely style the action bar.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.AppTheme.ActionBar</item>
    <item name="actionBarTheme">@style/ThemeOverlay.AppTheme.ActionBar</item>
    <item name="actionBarPopupTheme">@style/ThemeOverlay.AppTheme.PopupMenu</item>
</style>

覆盖操作栏样式以更改背景颜色或高度.

Override the action bar style to change the background color or elevation.

<style name="Widget.AppTheme.ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
    <!-- action bar background - without android prefix -->
    <item name="background">...</item>
    <!-- action bar elevation - without android prefix -->
    <item name="elevation">4dp</item>
</style>

覆盖操作栏主题以定义操作栏中所有视图的特殊行为,例如操作项、波纹背景颜色、文本颜色.

Override the action bar theme to define special behavior for all views inside the action bar such as action items, ripple background color, text color.

<style name="ThemeOverlay.AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <!-- title text color -->
    <item name="android:textColorPrimary">...</item>
    <!-- subtitle text color -->
    <item name="android:textColorSecondary">?android:textColorPrimary</item>
    <!-- action menu item text color -->
    <item name="actionMenuTextColor">?android:textColorPrimary</item>
    <!-- action menu item icon color -->
    <item name="colorControlNormal">?android:textColorPrimary</item>
</style>

您还可以更改弹出主题.

You can also change the popup theme.

<style name="ThemeOverlay.AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark">
    <!-- popup menu background - NEVER "android:background" !!! in themes -->
    <item name="android:colorBackground">...</item>
    <!-- popup menu item text color -->
    <item name="android:textColorPrimary">...</item>
</style>

另一方面,以下代码将允许您设置窗口的样式.

On the other hand, the following code will allow you to style the window.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- window background - NEVER "android:background" in themes !!! -->
    <item name="android:windowBackground">...</item>
    <item name="android:textColorPrimary">...</item>
    <item name="android:textColorSecondary">...</item>
</style>

您也可以直接更改操作栏上的文本颜色.但要小心!这不会影响菜单项或图标的文本颜色或波纹颜色!从长远来看,这可能不是您想要的.

You can also change text color on the action bar directly. But beware! This will not afffect text color of menu items or icons or ripple color! This is probably not what you want in the long run.

<style name="Widget.AppTheme.ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
    <!-- title text color -->
    <item name="titleTextColor">?android:textColorPrimary</item>
    <!-- subtitle text color -->
    <item name="subtitleTextColor">?android:textColorSecondary</item>
</style>

这篇关于在 android 上更改 AppCompat Light DarkActionBar 主题的背景和文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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