【问题标题】:Change background color of an android actionbar, base tutorial更改 android actionbar 的背景颜色,基础教程
【发布时间】:2013-11-27 22:52:07
【问题描述】:

我正在尝试按照 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 行:错误:错误:未找到与给定匹配的资源 名称: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>

有什么问题?

【问题讨论】:

  • 你在你的android项目中引用了app compact吗?
  • 你能贴出你如何解决的代码吗?

标签: android colors android-actionbar


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-07-25
    • 2015-08-14
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 2014-03-05
    • 2022-08-23
    • 1970-01-01
    • 2015-05-12
    相关资源
    最近更新 更多