0

我有一个活动和一个布局应用程序。我正在实现 ActionBarSherlock,但我的主题不适用于我的模拟器/早期设备。

我的主题.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- the theme applied to the application or activity -->
    <style name="CustomActivityTheme" parent="Theme.Sherlock">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <!-- other activity and action bar styles here -->
    </style>

    <!-- style for the action bar backgrounds -->
    <style name="MyActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="android:backgroundSplit">#4200ff</item>
        <item name="android:backgroundStacked">#4200ff</item>
        <item name="android:background">#4200ff</item>
    </style>


</resources>

这会导致我的 JellyBean 设备上的 ActionBar 变成蓝色,但在我的 2.2 模拟器上它保持黑色。

这是我的 manifest.xml 中的一段:

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActivityTheme">
4

1 回答 1

1

在 Android 3.0 及更高版本中,您可以将主题分配给项目名称android:actionBarStyle。但是在 2.3 和更早的版本中没有 Action Bar,所以你不能使用带有 name 的 item android:actionBarStyle。为了修复这个 ActionBarSherlock 已经定义了它自己的项目名称,只是actionBarStyle没有 android 前缀。
所以你的代码应该是这样的

<!-- the theme applied to the application or activity -->
<style name="CustomActivityTheme" parent="Theme.Sherlock">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>
    <!-- other activity and action bar styles here -->
</style>

<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="android:backgroundSplit">#4200ff</item>
    <item name="android:backgroundStacked">#4200ff</item>
    <item name="android:background">#4200ff</item>
</style>

于 2012-07-08T20:26:56.257 回答