我如何样式appcompat-V7工具栏一样Theme.AppCompat.Light.DarkActionBar? [英] How do I style appcompat-v7 Toolbar like Theme.AppCompat.Light.DarkActionBar?
问题描述
我试图重新 Theme.AppCompat.Light.DarkActionBar
的外观与新的支持库工具栏。
I'm trying to recreate the look of Theme.AppCompat.Light.DarkActionBar
with the new support library Toolbar.
如果我选择 Theme.AppCompat.Light
我的工具栏将是光,如果我选择 Theme.AppCompat
它会发暗。 (从技术上讲,你必须使用 .NoActionBar
的版本,但据我可以告诉唯一不同的是
If I choose Theme.AppCompat.Light
my toolbar will be light and if I choose Theme.AppCompat
it will be dark. (Technically you have to use the .NoActionBar
version but as far as I can tell the only difference is
<style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
现在有没有 Theme.AppCompat.Light.DarkActionBar
,但天真的我以为这会是不够好,只是让我自己
Now there's no Theme.AppCompat.Light.DarkActionBar
but naively I thought it'd be good enough to just make my own
<style name="Theme.AppCompat.Light.DarkActionBar.NoActionBar">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
不过这个我的工具栏仍然浅
主题。我已经花了几个小时,现在试图混合黑暗(基地)的主题和光主题的不同组合,但我只是找不到可以让我有浅色背景上的一切,但在工具栏的组合。
However with this my toolbars are still Light
themed. I've spent hours now trying different combinations of mixing the Dark (base) theme and the Light theme but I just can't find a combination that will let me have light backgrounds on everything but the toolbars.
有没有得到的 AppCompat.Light.DarkActionBar
的外观与进口 android.support.v7.widget.Toolbar $ C的方式$ C>的?
Is there a way of getting the AppCompat.Light.DarkActionBar
look with import android.support.v7.widget.Toolbar
's?
推荐答案
推荐的方法样式工具栏的 Light.DarkActionBar
克隆是使用 Theme.AppCompat.Light.DarkActionbar
父/应用的主题,并添加下列属性的风格隐藏默认的动作条:
The recommended way to style the Toolbar for a Light.DarkActionBar
clone would be to use Theme.AppCompat.Light.DarkActionbar
as parent/app theme and add the following attributes to the style to hide the default ActionBar:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后用下面的工具栏:
Then use the following as your Toolbar:
<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-&GT;安卓主题
和工具栏 - &GT;应用:popupTheme
。另外请注意,这将拿起你的?ATTR / colorPrimary
如果你把它设置在主风格,所以你可能会得到不同的背景色。
For further modifications, you would create styles extending ThemeOverlay.AppCompat.Dark.ActionBar
and ThemeOverlay.AppCompat.Light
replacing the ones within AppBarLayout->android:theme
and Toolbar->app:popupTheme
. Also note that this will pick up your ?attr/colorPrimary
if you have set it in your main style so you might get a different background color.
您会发现这是一个很好的例子是在一个空缺活动
Android的工作室目前的项目模板(1.4 +)。
You will find a good example of this is in the current project template with an Empty Activity
of Android Studio (1.4+).
这篇关于我如何样式appcompat-V7工具栏一样Theme.AppCompat.Light.DarkActionBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!