扩展列表视图的更改图标 [英] Change icon of expandable list view

查看:190
本文介绍了扩展列表视图的更改图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的可扩展列表视图的扩大和默认图标。
我做了一些研究如何做到这一点,并找到<一href=\"http://stackoverflow.com/questions/8293738/androidchange-indicator-icon-and-size-of-expandablelistview-used-for-navigation\">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>

这篇关于扩展列表视图的更改图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆