当我使用ActionBarSherlock时,如何应用HoloEverywhere Android主题?

12

我正在构建一个应用程序,它应该在Android 2.3上运行,并且我已经添加了ActionBarSherlock和HoloEverywhere库。

为了使用ActionBarSherlock,我必须像这样使用Theme.Sherlock:

<application
    ...
    android:theme="@style/Theme.Sherlock"
    ...  >

这没问题。

我的主要活动很简单:只是一个带有5行的ListView(我没有使用ListAcivity)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/menuListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

由于这是Android 2.3版本,所以我仍然使用橙黑色主题(ActionBar除外)。现在我想通过修改清单文件来添加HoloEverywhere主题:

<application
    ...
    android:theme="@style/Theme.HoloEverywhereDark.Sherlock"
    ...  >

但这并没有改变任何事情... 我错过了什么吗?


2
我需要像之前版本中的ICS一样的Spinner。但是我尝试导入ActionBarSherlock和Holoeverywhere。但是在Eclipse中导入后出现了很多错误。而且请告诉我,我们不能只使用Holoeverywhere而不使用ActionBarSherlock吗? - Vins
哪些错误?是的,您可以在不使用ActionBarSherlock的情况下使用Holoeverywhere。 - Alexis
类似于资源未找到的错误。我导入的步骤是->文件->新建项目->从现有代码导入Android项目。 - Vins
请检查R.java文件是否正确生成,有时会出现问题。另外,您应该将ActionBarSherlock项目在HoloEverywhere项目的属性中设置为库。 - Alexis
3个回答

7
为了使每个ListView默认启用Holo主题,我进入了HoloEverywhere库的styles.xml文件,然后修改了“ListViewStyle”元素,添加了以下行:
<item name="android:listSelector">@drawable/list_selector_holo_dark</item>

3

我遇到了与ListView选择器相同的问题。我认为HoloEveruwhere会默认应用holo选择器(蓝色)(我尝试过Theme.HoloEverywhereLight和Theme.HoloEverywhereLight),但实际上并没有。也许我漏掉了什么。

最终,我手动设置了选择器:

listView.setSelector(R.drawable.list_selector_holo_light);

在库中有几个可供使用的drawable资源(例如list_selector_holo_light)。


这实际上是有效的,但我必须为每个ListView都这样做。 - Alexis

2

一个便携且正确的解决方案是继承ListViewStyle并覆盖属性,在styles.xml中进行修改。

如果您在远程服务器上部署了HoloEverywhere官方库(例如Maven repo),则不能依赖于它保持styles.xml中的更改(您正在根据自己的需求进行修改)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接