我正在尝试使用新的支持库工具栏重新创建 Theme.AppCompat.Light.DarkActionBar
的外观。
如果我选择 Theme.AppCompat.Light
我的工具栏会变亮,如果我选择 Theme.AppCompat
它会变暗。 (从技术上讲,您必须使用 .NoActionBar
版本,但据我所知,唯一的区别是
<style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
现在没有 Theme.AppCompat.Light.DarkActionBar
但我天真地认为自己制作就足够了
<style name="Theme.AppCompat.Light.DarkActionBar.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
但是,我的工具栏仍然是 Light
主题。我已经花了几个小时尝试混合深色(基本)主题和浅色主题的不同组合,但我找不到一个组合可以让我在工具栏以外的所有东西上都有浅色背景。
有没有办法通过 import android.support.v7.widget.Toolbar
's 获得 AppCompat.Light.DarkActionBar
外观?
最佳答案
为 Light.DarkActionBar
克隆设置工具栏样式的推荐方法是使用 Theme.AppCompat.Light.DarkActionbar
作为父/应用主题并添加以下内容隐藏默认ActionBar的样式属性:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后将以下内容用作您的工具栏:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
如需进一步修改,您将创建扩展 ThemeOverlay.AppCompat.Dark.ActionBar
和 ThemeOverlay.AppCompat.Light
的样式,替换 AppBarLayout->android 中的样式:theme
和 Toolbar->app:popupTheme
。另请注意,如果您已将其设置为主要样式,这将获取您的 ?attr/colorPrimary
,因此您可能会获得不同的背景颜色。
您会在当前项目模板中找到一个很好的例子,其中包含 Android Studio (1.4+) 的 Empty Activity
。
关于android - 如何像 Theme.AppCompat.Light.DarkActionBar 一样设置 appcompat-v7 工具栏的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26503149/