2

我正在使用兼容性库 v7。

我只是想将我的操作栏的颜色(适用于 Android 2.1 及更高版本 - 尽管我运行 Android 4.4.2)设置为纯色。

但是颜色没有变化。它保持不变。

我也尝试过用颜色创建一个实体可绘制对象,但这也没有改变。

最后,我测试了是否可以更改布局的背景,并且我可以 - 它一定是关于我没有得到的操作栏背景。

这是代码:

    <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="CustomActionBarTheme"
           parent="@style/Theme.AppCompat.Light.DarkActionBar">

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">

         <item name="android:background">#0000ff</item>  

    </style>
</resources>
4

5 回答 5

1

这似乎对我有用。尝试使用资源而不是原始值。

<style name="app_theme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/app_action_bar</item>
</style>

<style name="app_action_bar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@color/google_lightest_gray</item>
    <item name="android:icon">@android:color/transparent</item>
    <item name="android:windowActionBarOverlay">false</item>
</style>
于 2014-04-05T08:23:30.313 回答
0

根据需要使用getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#808080")));inActivity extends SherlockActivity或颜色 :)

于 2014-04-05T08:22:50.370 回答
0

您可以使用:

getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorname));
于 2014-04-05T08:27:20.257 回答
0

使用以下代码getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg_color.xml));

actionbar_bg_color.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
      <solid android:color="@color/actionbar_bg"/>  <!-- set desired #0000ff color in color.xml
 you can use here solid color as well as gradient -->
 </shape>

希望这对你有帮助

于 2014-04-05T09:06:13.400 回答
0

我通过以下方式解决了它:

  • 正确安装 support-v7-appcompat 库。我的错误。
  • 将样式转移到每个版本的 res/values/styles.xml 文件,即一个用于向后兼容,一个用于 values-v11。

我不知道为什么我无法在themes.xml 中得到我想要的结果。

如果有人有答案,我将不胜感激

于 2014-04-05T09:26:58.500 回答