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

标签 android colors android-actionbar

我正在尝试根据 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

http://actionbarsherlock.com/

关于android - 更改 android 操作栏的背景颜色,基本教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19985945/

相关文章:

android - 在 Android 中何时开始新 Activity 以及何时重用旧 Activity

android - Android camera2 CameraCharacteristics API 对于传感器尺寸的可靠性如何?

android - 我可以在 Monodroid 中使用什么来替代 Action Bar?

android - 自定义 ActionBar 项目上的 ClickListener (ActionBarSherlock)

Android 应用程序将所需的权限转换为功能

android - 如何在不同进程中建立Activity和Service之间的双向通信?

css - 更改链接下划线颜色而不是字体颜色(底部边框不适用于所有浏览器)

ios - 在 spritekit 中更改节点颜色

colors - 确定 HSL 变化以将颜色转换为另一种颜色

java - 我如何在具有恒定项目位置的 ListView 上过滤项目?