Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 展开时,Expandablelistview背景变为黑色_Android_Expandablelistview - Fatal编程技术网

Android 展开时,Expandablelistview背景变为黑色

Android 展开时,Expandablelistview背景变为黑色,android,expandablelistview,Android,Expandablelistview,我在Android 2.3.5(可能还有更早的Android版本)上面临这个问题 当我的ExpnaTableListView折叠时,背景将正确显示。一组行展开后,其背景将变为黑色 这是列表视图 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertica

我在Android 2.3.5(可能还有更早的Android版本)上面临这个问题

当我的ExpnaTableListView折叠时,背景将正确显示。一组行展开后,其背景将变为黑色

这是列表视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
android:background="@drawable/bg"
>

    <TextView  
        android:id="@+id/ExpandableListText"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textColor = "#490600"
        android:paddingRight = "25sp"
        android:paddingLeft = "25sp"
    />

    <ExpandableListView 
        android:id="@+id/ExpandableListView01" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:divider="#000000"
        android:dividerHeight="1sp"
        android:childDivider="#000000"
        android:headerDividersEnabled="true"
        android:footerDividersEnabled="true"
        android:scrollingCache="false"
        android:cacheColorHint="#00000000"
         android:drawSelectorOnTop="true"
    />
</LinearLayout>

下面是分组行的XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

>

    <TextView
        android:id="@+id/TextViewGroup" 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginLeft="50sp"
        android:gravity="center_vertical"
        android:textColor = "#490600"
        android:paddingTop="7dip"
        android:paddingBottom="7dip"
    ><!--  -->
    </TextView>

</LinearLayout>

下面是子行XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

>
 <!-- android:background="#666666" -->
    <!--  -->
    <TextView
        android:id="@+id/TextViewChild01" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30sp"
        android:textColor = "#000000"
    >
    </TextView>

    <TextView
        android:id="@+id/TextViewChild02" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:textColor = "#000000"
    >
    </TextView>

    <TextView
        android:id="@+id/TextViewChild03" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:textColor = "#000000"
    >
    </TextView>

</LinearLayout>


非常感谢您的帮助

定制您的ExpandableListView类,然后-

package com.test
//....................

View getView(.....) {
   View v = super.getView(....);

   //........
   //change it your color or or set the text you want.
   return(v);
}
然后将其设置到您的布局中-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
>

<TextView  
    android:id="@+id/ExpandableListText"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor = "#490600"
    android:paddingRight = "25sp"
    android:paddingLeft = "25sp"
/>

<com.test.ExpandableListView 
    android:id="@+id/ExpandableListView01" 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:divider="#000000"
    android:dividerHeight="1sp"
    android:childDivider="#000000"
    android:headerDividersEnabled="true"
    android:footerDividersEnabled="true"
    android:scrollingCache="false"
    android:cacheColorHint="#00000000"
     android:drawSelectorOnTop="true"
/>


开始创建新视图之前,请确保已在布局文件中为视图设置了“缓存颜色提示”属性。在选择/滚动期间,该属性应设置为您首选的背景色,否则视图将默认为黑色。

我也有同样的问题,很可能它是2.3版本上的一个bug,并与android:childDivider=“#000000”,只要删除它,黑色背景就会消失。

在Suvam Roy的回答上展开,对我来说有效的是确保从GetChildView返回的子视图的背景在代码或相关的布局文件中被显式指定(无论使用哪种技术定义视图)

这样做的缺点是会丢失默认项单击高亮显示。将背景设置为选择器drawable很容易,但我还无法复制淡出效果(即使将所有android内置drawable复制到我的应用程序空间中)

作为参考,大多数列表的默认可绘制列表(提供了带有淡出效果的漂亮点击高亮显示)为

最后,只需将ExpandableListView上的cacheColorHint设置为“#00000000”(半透明)


谢谢Suvam……那不行。我仍然得到黑色的部分…如果我添加Packagename.expandablelistview应用程序强制关闭…是否可能有示例getview代码?在customize类中,您应该覆盖所有构造函数和getview方法,然后将其自定义到getview方法中。这意味着创建一个类并扩展expandableListview。这个类名应该出现在你的布局页面中。感谢你的时间…我是android新手。你能在getview中提供一个例子或任何链接吗?我应该膨胀什么…孩子或组?好的,找到了解决方案…不需要getview(…)。如果您正在自定义可扩展的listview,那么在这些功能中可能有getGroupView(…)和getChildView(…),使用convertView将setbackground设置为convertView.setBackgroundColor(Color.parseColor(#fff0e1));只是想澄清一下,ListView(即ExpandableListView)本身上的cacheColorHint是#00000000
Android.Resource.Drawable.ListSelectorBackground