Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change icon of expandable list view

I would like to change the expanded and default icon of my Expandable List View. I did some research how to do this and found this question.

I think I did it just as it is described there. I have 2 icons, the first is called defaulticon.png and the second one expandedicon.png. Bother are located in the drawable folder (not in drawable-hdpi). My list view declaration looks like this:

<ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:groupIndicator="@drawable/groupindicator">
    </ExpandableListView>

The groupindicator is an xml file also located in the drawable folder and looks like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@drawable/defaulticon" android:state_empty="true"/>
   <item android:drawable="@drawable/expandedicon" android:state_expanded="true"/>
</selector>

However the icons do not change. The default icon from the list view disappears and instead there is no icon. Are there any restrictions with the resources (how big the resources can me (both are 160x160), where they have to be located,...). I am testing the app on my S3 running Android 4.1.2.

Cheers

like image 761
productioncoder Avatar asked Sep 08 '13 14:09

productioncoder


1 Answers

Change your icon size to 32 X 32, put your icon in drawable-mdpi and then try this code

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:drawable="@drawable/expandedicon" android:state_expanded="true"/>
       <item android:drawable="@drawable/defaulticon"/>
    </selector>
like image 199
Antarix Avatar answered Oct 15 '22 05:10

Antarix