Reputation:
I am making an app in which i have to use given images for expandable list view .Actully i am talking of indicator icon and its size which navigate the path.Can anyone tell me how to change that image .Any help will be appreciated.
Upvotes: 6
Views: 35997
Reputation: 51
Try using this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_up_arrow" android:state_expanded="true" />
<item android:drawable="@drawable/ic_down_arrow" android:state_pressed="false"/>
</selector>
Upvotes: 0
Reputation: 1
It's correct, check my app
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
android:divider="@android:color/darker_gray"
android:groupIndicator="@drawable/select_next"
android:dividerHeight="0.5dp" />
Use follow below like this....
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_add_black_24dp"
android:state_empty="true" />
<item android:drawable="@drawable/ic_remove_black_24dp"
android:state_expanded="false" />
</selector>
Upvotes: 0
Reputation:
You can use the following code:
<ExpandableListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:groupIndicator="@drawable/settings_selector" />
... where the setting_selector
is:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/up_arrow"
android:state_empty="true" />
<item android:drawable="@drawable/down_arrow"
android:state_expanded="true" />
</selector>
Upvotes: 35
Reputation: 1478
<ExpandableListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:groupIndicator="@drawable/settings_selector"
/>
And
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/up_arrow" android:state_expanded="true"/>
<item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>
</selector>
He forgot to put
<item android:drawable="@drawable/down_arrow" android:state_expanded="false"/>
in it.
For me, android:state_empty
not working.
Upvotes: 16
Reputation: 2186
this is efficient way to set group indicator
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_empty="true">
<layer-list>
<item
android:left="20dp"
android:right="-30dp"
android:top="120dp"
android:bottom="10dp"
android:drawable="@drawable/panier_plus">
</item>
</layer-list>
</item>
<item android:state_expanded="true">
<layer-list>
<item
android:left="20dp"
android:right="-30dp"
android:top="120dp"
android:bottom="10dp"
android:drawable="@drawable/panier_minus"
>
</item>
</layer-list>
</item>
Upvotes: 7
Reputation: 5900
If you mean the expand/collapsed group icon then
Drawable d = getResources().getDrawable(R.drawable.settings_selector);
//position it in the group layout by setting the bounds
//params are left and right bounds
myExpandableList.setIndicatorBounds(345,375);
myExpandableList.setGroupIndicator(d);
I'm not too sure about the size of the indicator, setting the indicator bounds can affect the width of the indicator but not the height.
You could remove the indicator by setting the drawable to null, then inflate a custom layout with an image view in it in getGroupView() in the ExpandableAdapter.
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View convertView = null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.customLayout, null);
return convertView;
}
Although this method would require some extra work to get the indicator to change when the group is expanded, such as a listener to tell whether or not a particular group is expanded and change the image accordingly.
Upvotes: 1