繁体   English   中英

正确的造型方式Android Lollipop 5.0工具栏

[英]Correct way of styling Android Lollipop 5.0 Toolbar

我一直在敲打这个问题一段时间没有任何运气。 我在我的应用程序(支持Android API 11及更高版本)中使用android.support.v7.widget.Toolbar ,并想要设置样式。 以下是我的尝试方式:

我的活动布局XML包含:

        <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:theme="?attr/foo" />

res / values / attr.xml包含(这是我定义属性的地方):

        <attr name="foo" format="reference" />

res / values / Themes.xml

    <style name="AppTheme" parent="Theme_one">
    </style>
    <style name="Theme_one" parent="@style/Theme.AppCompat.Light">
        <item name="windowActionBar">false</item> 
        <item name="foo">@style/foo_style</item>
        <!-- bunch of other styles -->
    </style>

res / values / Styles.xml

<style name="foo_style" parent="@style/Theme.AppCompat.Light">
    <item name="android:background">@color/actionBarDark</item>
</style>

res / values-v21 / Themes.xml

<style name="AppTheme" parent="Theme_one">
    <!-- some v21 specific items not related to toolbar like animations etc-->
</style>

res / values-v21 / Styles.xml

<style name="foo_style" parent="@style/Theme.AppCompat.Light">
    <item name="android:colorPrimaryDark">@color/actionBarDark</item> <!-- THIS DOES NOT WORK !!! -->
    <item name="android:background">@color/actionBarDark</item>
    <item name="android:elevation">5dp</item>
</style>

这种安排适用于Android API v11到v19。 我的问题为v21(我也试过2和3没有android:前缀相同的结果):

1) android:后台工作正常!
2) android:colorPrimaryDark不起作用!
3) android:elevation适用于Toolbar的标题和Toolbar按钮,如下所示。 这是预期的吗?
在此输入图像描述

我错过了什么? 很明显,我没有正确的方式做样式,但无法找到任何谈论toolbar样式的资源!

通过移动:我得到了colorPrimaryDark来工作:

<item name="colorPrimaryDark">@color/actionBarDark</item>

res / values-v21 / Styles.xmlres / values-v21 / Themes.xml

我通过从所有样式或主题xmls中删除它并将其放入android.support.v7.widget.Toolbar声明中来提升高程

此外,如果我在此处定义另一个主题并使用Content.setTheme()在应用程序中动态更改主题,则主题会更改,但状态栏颜色不会更改。 欢迎任何建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM