How do I apply the HoloEverywhere android theme wh

2019-03-11 06:33发布

问题:

I'm building an application that should work on android 2.3 and I added both ActionBarSherlock and HoloEverywhere libraries.

In order to use ActionBarSherlock I have to use Theme.Sherlock like so :

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

And that's ok.

My main activity is pretty simple : just a ListView with 5 rows (I don't use 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>

Since it's android 2.3, I still have the orange&black theme (except for the ActionBar of course). Now I want to add the HoloEverywhere theme by modifying my manifest like so :

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

BUT that does not change anything... What am I missing ?

回答1:

To enable the Holo theme by default for every ListView I went in the styles.xml file of the HoloEverywhere library then I modified the "ListViewStyle" element by adding this line :

<item name="android:listSelector">@drawable/list_selector_holo_dark</item>


回答2:

I had the same issue with ListView's selector. I though that HoloEveruwhere would apply holo selector(blue) by default(I have tried both Theme.HoloEverywhereLight and Theme.HoloEverywhereLight), but it didn't. Maybe I am missing something.

I ended up setting the selector manually:

listView.setSelector(R.drawable.list_selector_holo_light);

You have several drawable resources in the library you can make use of(list_selector_holo_light for example).



回答3:

A portable and correct solution would be to inherit from ListViewStyle and override the attribute, making this in your styles.xml.

If you had HoloEverywhere official library deployed remotely on a server (e.g. Maven repo) you could not depend on it mantaining a change in the styles.xml (you are modifying it for your own needs).