【问题标题】:How to highlight ExpandableListView group on group expansion via xml?如何通过 xml 在组扩展中突出显示 ExpandableListView 组?
【发布时间】:2014-05-05 10:52:52
【问题描述】:

我想在 ExpandableListView 打开时突出显示组视图。我意识到我需要制作选择器。我可以在 XML 布局中使用组选择器吗?

【问题讨论】:

    标签: android xml expandablelistview


    【解决方案1】:

    ExpandableListView 有一个名为 android:listSelector 的属性,您可以传递一个选择器,但是我找不到可以在 Group 是否展开时使用的状态。使用 android:state_pressed 似乎在 groupItem 被触摸时起作用,但在释放它后,它的状态又回来了,高亮消失了。

    我最终做的是检查 ExpandableListView Adapters getGroupView 函数中的 isExpanded 值,并根据该值设置返回的 Views 背景:

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = infalInflater.inflate.....;
        }
        if(isExpanded){
           convertView.setBackgroundResource(R.drawable.listgroup_background_active);
        }else{
            convertView.setBackgroundResource(R.drawable.listgroup_background);
        }
        return convertView;
    }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 2017-03-21
      相关资源
      最近更新 更多