扩展列表视图的更改图标视图、图标、列表

2023-09-07 23:08:26 作者:蓝颜∨妖精

我想改变我的可扩展列表视图的扩大和默认图标。我做了一些研究如何做到这一点,并找到this问题。

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.

我想我这样做只是因为它是有描述。我有2个图标,第一个被称为defaulticon.png,第二个expandedicon.png。懒得位于绘制的文件夹(而不是在绘制 - 华电国际)。我的列表视图声明如下所示:

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>

该groupindicator是一个XML文件也位于绘制文件夹,如下所示:

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>

然而图标不改变。从列表视图中的默认图标消失,反而没有图标。是否存在与资源的任何限制(有多大的资源我(均为160x160的),在那里他们将位于...)。我测试在运行Android 4.1.2我S3的应用程序。

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.

干杯

推荐答案

更改图标的大小为32×32,把你的图标绘制-MDPI ,然后试试这个code

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>