android:change indicator icon and size of expandablelistview used for navigation

后端 未结 6 1545
梦谈多话
梦谈多话 2020-12-13 16:34

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

相关标签:
6条回答
  • 2020-12-13 16:59
    <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.

    0 讨论(0)
  • 2020-12-13 17:05

    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>
    
    0 讨论(0)
  • 2020-12-13 17:08

    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>
    

    0 讨论(0)
  • 2020-12-13 17:10

    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>
    
    0 讨论(0)
  • 2020-12-13 17:11

    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.

    0 讨论(0)
  • 2020-12-13 17:15

    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>
    
    0 讨论(0)
提交回复
热议问题