我一直在抱怨这一段时间,现在没有任何运气。 我在我的应用程序(支持Android API 11及以上版本)中使用android.support.v7.widget.Toolbar
,并且想要设计它。这是我如何我尝试它:正确的造型方式Android Lollipop 5.0工具栏
我的动态布局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 /价值/ attr.xml包含(这是我定义我的属性):
<attr name="foo" format="reference" />
RES /值/的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 /值/ Styles.xml:
<style name="foo_style" parent="@style/Theme.AppCompat.Light">
<item name="android:background">@color/actionBarDark</item>
</style>
RES /值-V21 /的themes.xml:
<style name="AppTheme" parent="Theme_one">
<!-- some v21 specific items not related to toolbar like animations etc-->
</style>
RES /值-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)安卓背景正常工作!
2)android:colorPrimaryDark不起作用!
3)android:海拔适用于Toolbar
和Toolbar
按钮的标题,如下所示。这是预期的吗?
我在想什么?显然,我没有按照正确的方式做造型,但无法找到谈论toolbar
造型的任何资源!
尝试删除父=“@ style/Theme.AppCompat。Light“from your foo_style – 2014-11-09 07:08:12
这没有什么区别,我在工具栏声明中添加它,然后更新了答案 – rgamber 2014-11-09 08:23:45
你不应该在新的支持库中为它们中的任何一个使用android前缀。阅读:https://chris.banes.me/2014/10/17/appcompat-v21/ – 2014-11-11 18:14:15