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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With