我在我的应用程序中使用ExpandableListView
,我从用户那里得到的一个抱怨是,当List
项目被展开时,很难在视觉上区分子项目的结束位置和下一个组项目的开始位置。
因此,我想将子List
项的背景更改为不同的阴影。
到目前为止,我所做的粗暴尝试都是基于直接更改子View
项中元素的背景颜色和文本,但这会导致悬停和高亮显示的丢失。所以我的问题是,什么是实现上述目标的好策略?
我尝试了styles
和selectors
,但真正让我头疼的是,如果我改变了子项的背景,那么我就需要为焦点/启用等的所有组合添加selectors
。
有没有办法继承父style
并仅为未聚焦的、已启用的子项设置background
,并保留其他styles
?
发布于 2009-12-15 19:02:48
井。以下是对我有效的方法:
res/drawable
目录中创建list_background.xml ExpandableListAdapter#getChildView
中创建可展开列表的子视图时使用的xml布局文件
这是完整的可绘制文件
<?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>
我必须将/android-sdk-windows-1.6_r1/platforms/android-1.5/data/res/drawable
中的list_highlight_active.xml
和list_highlight_inactive.xml
复制到项目的可绘制目录中。@color/item_body
只是一个灰色的阴影
发布于 2010-04-06 02:56:50
我刚刚发现了一种方法,可以“有点”地设置背景颜色,而不必跳过选择器的圈子。
正如您已经注意到的,将背景设置为纯色会清除选择器的高亮显示,因为新的背景颜色会使其变得模糊。Droidin有一个正常的解决方案:为你自己的背景选择器提供你想要的确切颜色。至少可以说,这是一种痛苦。
但是,如果你想要的只是稍微区分一下颜色,那么有一种更简单的方法: alpha混合。使用alpha值设置背景颜色。例如,将背景设置为"#BBFFFFFF“。前两个数字表示alpha级别。它会混合在一起,所以背景不会是纯白色的,选择的高光也不会是普通的亮橙色,但是孩子们会是不同的颜色,高亮仍然有效。双赢。
发布于 2014-03-13 12:52:23
我在寻找类似的解决方案。您可以尝试在适配器方法getChieldView上获取父视图。我认为这位家长是你所有孩子的家长观点。并将资源中的背景设置为此父对象。我是这样做的:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fa_report_sub_item, null);
View parentGroup=(View) convertView.getParent();
parentGroup.setBackgroundResource(R.drawable.fa_summ_report_main_item);
}
https://stackoverflow.com/questions/1903683
复制相似问题