Android的 - ExpandableListView变化背景子项 [英] Android - ExpandableListView change background for child items

查看:216
本文介绍了Android的 - ExpandableListView变化背景子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 ExpandableListView 我的应用程序和投诉,我从用户得到一个是
列表项目展开很难从视觉上分辨那里的孩子
项目结束,下一个组项开始。

I'm using ExpandableListView in my app and one of the complaints I get from the users is that when the List item is expanded it's hard to visually distinguish where the child item ends and next group item begins.

所以我想改变孩子的背景列表项不同的阴影。

So I would like to change the background of the child List item to the different shade.

这是我迄今为止所取得是基于直接改变背景颜色和元素的文本子查看项目内,但,导致悬停的损失和野蛮的企图强调。所以我的问题是 - 什么是一个很好的策略,以实现上述

Brutal attempts that I've made so far were based on directly changing background color and text of the elements inside the child View item but that leads to loss of hovers and highlights. So my question is - what is a good strategy to achieve the above?

我试过风格选择但真正的流浪汉我是,如果我更改子项的背景,然后我需要添加选择焦点的所有组合/启用等。当所有我想这样做是为了覆盖一个单一的东西。

I tried styles and selectors but what really bums me is if I change background for child item then I need to add selectors for all combinations of focus/enabled etc. When all I'm trying to do it to overwrite a single thing.

有没有办法继承父风格并设置背景仅针对非重点,启用了子项其他风格保留?

Is there a way to inherit parent style and set background only for non-focused, enabled child item with other styles retained?

推荐答案

嘛。下面是我工作:


  1. 创建在项目的水库list_background.xml /绘制目录

  2. 您的子项的顶层布局上面绘制的设置背景值。如果你在这一点摸不着头脑了 - 我指的是当您创建 ExpandableListAdapter#getChildView
  1. Create list_background.xml in your project's res/drawable directory
  2. Set background value of the top level layout of your child item to the drawable above. If you are scratching your head at this point - I'm referring to the xml layout file that get's used when you create child view of your expandable list in ExpandableListAdapter#getChildView

下面是完整的绘制文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:state_enabled="true"
        android:drawable="@drawable/list_highlight_active" />
    <item android:state_enabled="true" android:state_selected="true" 
        android:state_window_focused="true"
    android:drawable="@drawable/list_highlight_inactive" />
    <item android:state_enabled="true" android:state_window_focused="true" 
        android:drawable="@color/item_body" />
    <item android:drawable="@color/item_body" />
</selector>

我不得不复制 list_highlight_active.xml list_highlight_inactive.xml / android- SDK-Windows的1.6_r1 /平台/ Android的1.5 /数据/ RES /绘制来我的项目的绘制目录。 @色/ item_body 只是一个灰色阴影

I had to copy list_highlight_active.xml and list_highlight_inactive.xml from /android-sdk-windows-1.6_r1/platforms/android-1.5/data/res/drawable to the drawable directory of my project. @color/item_body is just a shade of gray

这篇关于Android的 - ExpandableListView变化背景子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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