Android的Theme.AppCompat.Light与黑暗的工具栏(光文) [英] Android Theme.AppCompat.Light with Dark Toolbar (for light text)

查看:985
本文介绍了Android的Theme.AppCompat.Light与黑暗的工具栏(光文)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Theme.AppCompat.Light,我需要用这么对话框有光主题的应用程序。但是,这使得我的工具栏文本的黑色,在那里我宁愿它是白色的。我试过设置工具栏上的具体应用:主题AppCompat.Dark.Actionbar,但没有运气...我搜索了一段时间,但没有找到一个具体的问题,并回答这个

下面是我的默认AppTheme:

 <样式名称=AppTheme.Parent父=Theme.AppCompat.Light.NoActionBar>
    <项目名称=colorPrimary> @色/蓝< /项目>
    <项目名称=colorPrimaryDark> @色/ dark_blue< /项目>
    <项目名称=colorAccent> @色/粉色< /项目>

    <项目名称=机器人:windowNoTitle>真< /项目>
    <项目名称=windowActionBar>假< /项目>
< /风格>
 

下面是我的toolbar.xml:

 < android.support.v7.widget.Toolbar
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:ATTR / colorPrimary后台=
    机器人:=了minHeight@扪/ abc_action_bar_default_height_material
    应用程序:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar
    应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>
 

解决方案

为了改变标题的颜色在你的工具栏您只需添加属性机器人:textColorPrimary 您的工具栏风格

请参见下面的例子为工具栏,甚至更多的属性。

示例

 <样式名称=MyToolbarStyle父=ThemeOverlay.AppCompat.ActionBar>
    <! - 用于为工具栏的标题 - >
    <项目名称=机器人:textColorPrimary>#FFF< /项目>
    <! - 用于为工具栏的冠军时,家长Theme.AppCompat.Light  - >
    <项目名称=机器人:textColorPrimaryInverse>#FFF< /项目>
    <! - 用于着色的操作菜单图标的文字 - >
    <项目名称=机器人:textColorSecondary>#FFF< /项目>
    <! - 用于着色溢出菜单图标 - >
    <项目名称=actionMenuTextColor>#FFF< /项目>
    <! - 工具栏的颜色 - >
    <项目名称=机器人:背景>#455a64< /项目>
< /风格>
 

结果

I have an app using Theme.AppCompat.Light which I need to use so Dialogs have the light theme. But this makes the text in my toolbar black, where I'd rather it be white. I've tried setting the toolbar's specific app:theme to AppCompat.Dark.Actionbar, but no luck... I searched around for a while and couldn't find a specific question and answer to this.

Here's my default AppTheme:

<style name="AppTheme.Parent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/blue</item>
    <item name="colorPrimaryDark">@color/dark_blue</item>
    <item name="colorAccent">@color/pink</item>

    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Here's my toolbar.xml:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="@dimen/abc_action_bar_default_height_material"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

解决方案

In order to change the color of the title in your Toolbar you simply have to add the attribute android:textColorPrimary to your Toolbar style.

Please see the following example for even more attributes of the Toolbar.

Example

<style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar">
    <!-- Used to for the title of the Toolbar -->
    <item name="android:textColorPrimary">#fff</item>
    <!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light -->
    <item name="android:textColorPrimaryInverse">#fff</item>
    <!-- Used to color the text of the action menu icons -->
    <item name="android:textColorSecondary">#fff</item>
    <!-- Used to color the overflow menu icon -->
    <item name="actionMenuTextColor">#fff</item>
    <!-- Color of the Toolbar -->
    <item name="android:background">#455a64</item>
</style>

Result

这篇关于Android的Theme.AppCompat.Light与黑暗的工具栏(光文)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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