造型的Android操作栏 [英] Styling Android Action Bar
问题描述
我有一个新创建的项目,我想要做的第一件事情就是添加和风格的操作栏。我在他们的官方教程使得他们告诉的方式,甚至尝试了一些其他的方法,但我不能使它工作。 多次尝试后,我决定做一些很基本的,但即使这样,我不能使它发挥作用。 这是我有:
I've a newly created project and the first thing I want to do is add and style an action bar. I made it the way they tell in their official tutorials and even tried some other ways but I just can't make it work. After many tries, I decided to do something really basic but even like that I can't make it work. This is what I have:
styles.xml
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/blue</item>
</style>
manifest.xml的
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
另一个问题是,什么是@android的区别:款式/ Theme.Holo,@款式/ Theme.AppCompat.Light.DarkActionBar或者干脆Theme.AppCompat.Light.DarkActionBar
Another question is what is the difference between the @android:style/Theme.Holo, @style/Theme.AppCompat.Light.DarkActionBar or simply Theme.AppCompat.Light.DarkActionBar?
感谢。
推荐答案
按照利用材料的主题培训,材料主题(和AppCompat主题的这反向移植/使用材料的主题化)使用 colorPrimary
着色操作栏。因此,你的主题可以是:
Per the Using the Material Theme training, the Material theme (and AppCompat theme's which backport / use Material theming) use colorPrimary
to color the action bar. Therefore your theme can be:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/blue</item>
</style>
您会发现更多的细节如何主题使用AppCompat /材料中的 AppCompat V21博客帖子和的这个亲尖
You'll find more details on how to theme using AppCompat / Material in the AppCompat v21 blog post and in this pro-tip
这篇关于造型的Android操作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!