4

我正在尝试按照 android 教程(此处)更改由 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 行:错误:错误:找不到与给定名称匹配的资源:attr '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>

有什么问题?

4

1 回答 1

5

要使用低于 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

http://actionbarsherlock.com/

于 2013-11-14T18:56:20.137 回答