我正在尝试根据 android 教程 (here) 更改 由 Eclipse 向导制作的新 Android 应用程序 的 ActionBar 颜色,但我遇到了几个问题。
我设置minSdkVersion为10(应该是android 2.1左右)
当我将此代码粘贴到 themes.xml 时(如教程所述):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@style/AppTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/AppTheme">
<item name="android:background">#FFFFFF</item>
<!-- Support library compatibility -->
<item name="background">#FFFFFF</item>
</style>
</resources>
Eclipse 给我这些错误:
- 第 5 行:android:actionBarStyle 需要 API 级别 11(当前最低为 10)
- 第 8 行:错误:错误:找不到与给定匹配的资源 名称:属性“actionBarStyle”。
- 第 16 行:错误:错误:找不到资源 匹配给定名称:attr 'background'。
我修改了一些小东西(基本主题和颜色),但是干净的代码在教程中。
我的 Styles.xml 在这里:
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
有什么问题?
最佳答案
要在 api 级别 11 以下使用操作栏,您需要在您的项目中引用 app compact(来自支持库)。
您的类需要扩展 ActionBarActivity
并且您需要使用 Theme.AppCompat
。
http://developer.android.com/guide/topics/ui/actionbar.html
也检查这个
http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html
或者你需要使用ActionBarSherlock
关于android - 更改 android 操作栏的背景颜色,基本教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19985945/