ActionBar 颜色变化也 ListView 颜色

ActionBar color change also ListView color

当我尝试通过

更改 ActionBar 的颜色时,我的应用程序中发生了一些奇怪的事情
<style name="CustomAppTheme" parent="Theme.AppCompat.Light">
    <item name="android:background">#ff00</item>
    <item name="android:textColor">#DCDCDC</item>
</style>

也改变了我的 ListView 的颜色,在其他 activity 中改变了下面的全部内容。这是为什么?如何解决这个问题?

列表视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/listviewbackground"
android:orientation="vertical" >

<ListView
    android:id="@+id/list"
    android:longClickable="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
</ListView>

在覆盖 default color & styles of the action bar 方面,文档非常简单明了。我假设您可能正在 res/values/styles.xml 处更改应用程序的资源样式文件。我还假设在您的 AndroidManifest.xml 中,您将以下 属性 应用于 application 标签:

android:theme="@style/AppTheme"

同样,来自 documentation

A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.

因此,当您更改 styles.xml 文件时,您无意中更改了应用中所有元素的背景颜色。

按照 link 1 的说明进行操作,一切都会好起来的。具体来说,

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>
</resources>