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

8
我想要更改可扩展列表视图的展开和默认图标。我研究了如何做到这一点,并找到了这个问题
我认为我按照那里描述的方式做了。我有两个图标,第一个叫做defaulticon.png,第二个叫做expandedicon.png。两者都位于drawable文件夹中(而不是drawable-hdpi)。我的列表视图声明如下:
<ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:groupIndicator="@drawable/groupindicator">
    </ExpandableListView>

groupindicator 是一个 xml 文件,也位于 drawable 文件夹中,内容如下:

<?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上测试该应用程序。

干杯

2个回答

6

将您的图标大小更改为32 X 32,将您的图标放在drawable-mdpi中,然后尝试以下代码

<?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>

我在Eclipse中使用图标创建向导来制作上/下箭头,它们在Lollipop 5.1.1上运行良好。 - droideckar

-1
首先,将您的图像调整为24*24大小,然后将其复制到Android中的drawable-mdpi文件夹中。之后,复制并粘贴以下代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:drawable="@drawable/abc"android:state_empty="true"></item>
  <item android:drawable="@drawable/downarrow" ></item>
</selector>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接