eclipse 为 ExpandableListView 设置自定义指示器不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18904373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:11:50  来源:igfitidea点击:

Setting a custom indicator for ExpandableListView isn't working

androidxmleclipseexpandablelistview

提问by Guy

So I'm trying to set a custom ExpandableListView indicator icon but it isn't working. I created an icon and saved it to drawable folder. Here are the icons:

所以我试图设置一个自定义的 ExpandableListView 指示器图标,但它不起作用。我创建了一个图标并将其保存到 drawable 文件夹中。以下是图标:

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

This is the selector:

这是选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/arrow_up" android:state_empty="true"/>
    <item android:drawable="@drawable/arrow_down" android:state_activated="true"/>
</selector>

ExpandableListView xml:

可扩展列表视图 xml:

<ExpandableListView
    android:id="@+id/lvExp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:groupIndicator="@drawable/custom_arrow" />

However, when I launch the app, there is not indicator at all. Any idea what I have done wrong?

但是,当我启动应用程序时,根本没有指示器。知道我做错了什么吗?

回答by tyczj

this should do the trick

这应该可以解决问题

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_expanded="true" android:drawable="@drawable/arrow_up" />
    <item android:drawable="@drawable/arrow_down" />
</selector>

you wanted the state_expandedfor when the row gets expanded and then any other state besides expanded is just the normal down arrow. You should however handle the state_emptywhen there is nothing to expand to

state_expanded当行被扩展时,你想要for ,然后除了扩展之外的任何其他状态只是正常的向下箭头。然而,state_empty当没有什么可扩展的时候,你应该处理

回答by ecem

I think you just need to add this one line to your selector and change the arrow down condition:

我认为您只需要将这一行添加到您的选择器并更改向下箭头条件:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/arrow_up" android:state_empty="true"/>
    <item android:drawable="@drawable/arrow_down" android:state_expanded="true"/>
    <item android:drawable="@drawable/arrow_up" />
</selector>