【发布时间】:2017-02-23 19:21:20
【问题描述】:
我遇到了以下问题:我正在尝试实现像 instagram 这样的应用设计,其中大多数应用都使用浅色主题。但是,我还没有找到将工具栏文本和图标元素(如导航抽屉和后退按钮黑色)着色的方法。
当使用下面的style.xml时
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FAFAFA</item>
<item name="colorPrimaryDark">#BDBDBD</item>
<item name="colorAccent">#FF4081</item>
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Used to for the title of the Toolbar -->
<item name="android:textColorPrimary">@color/black</item>
<!-- Used to for the title of the Toolbar when parent is Theme.AppCompat.Light -->
<item name="android:textColorPrimaryInverse">@color/black</item>
<!-- Used to color the text of the action menu icons -->
<item name="android:textColorSecondary">@color/black</item>
<!-- Used to color the overflow menu icon -->
<item name="actionMenuTextColor">@color/black</item>
</style>
</resources>
工具栏的这个属性:
android:theme="@style/ToolbarTheme"
它产生以下设计:
如您所见,导航抽屉是白色的,标签标题也是白色的。
我也尝试过这种风格,它可以正常工作,但前提是你没有像这样在你的活动中明确设置工具栏:
活动代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
样式.xml:
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
当使用这种没有明确工具栏的样式时,设计看起来像我想要的,但是,我不能以这种方式调用工具栏。如果使用 Theme.AppCompat.Light 设置工具栏,则会抛出错误。
还要注意两种样式的区别:Theme.AppCompat.Light vs Theme.AppCompat.Light.NoActionBar
关于如何做到这一点的任何想法?
【问题讨论】:
标签: android xml android-toolbar android-styles