Android的定制AppCompat动作条 [英] Android customize AppCompat ActionBar
问题描述
我看到的这个多线程的,但我无法找到解决我的问题。我想创建一个自定义操作栏,以便开始我只是想简单的东西像刚才自定义颜色:
I have seen multiple threads on this but I am unable to find the solution to my problem. I want to create a custom action bar so to begin I just tried something simple like just a custom color:
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
然后在我的清单
我:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
我的 MainActivity
也扩展ActionBarActivity
我得到了一个错误说我需要办理 Theme.AppCompat
我的活动
但我没有再收到该错误。我的应用程序编译和运行,但在操作栏仅仅是标准的黑色,而不是红色(#FF0000)。
I was getting an error saying that I need to apply Theme.AppCompat
to my Activity
but I am no longer getting that error. My application compiles and runs but the action bar is just standard black, not red (#FF0000).
最后,我要让我的行动吧透明的,但我想我会得到这个整理出来的第一。任何帮助将是AP preciated。
Eventually I want to make my action bar transparent but I figured I would get this sorted out first. Any help would be appreciated.
推荐答案
由于在的文档,复古兼容性,您应使用 actionBarStyle
以及安卓actionBarStyle
:
As said in the documentation, for retro-compatibility, you should use actionBarStyle
along with android:actionBarStyle
:
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#FF0000</item>
</style>
这篇关于Android的定制AppCompat动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!