更改android操作栏的背景颜色,基础教程

Ply*_*nie 4 android colors android-actionbar

我试图在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

有什么问题?

Rag*_*dan 5

要使用api level 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/