Expandablelistview background turns black when expanding
I ran into this issue on Android 2.3.5 (and possibly earlier versions of Android)
When my expnadablelistview is reset, the background is displayed correctly. As soon as one group of lines expands, its background turns black.
Here is a list
<?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>
Here is the XML for the group string
<?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>
Following is the description of child_row 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>
Any help is appreciated
source to share
Set up your ExpandableListView class and then -
package com.test
//....................
View getView(.....) {
View v = super.getView(....);
//........
//change it your color or or set the text you want.
return(v);
}
and then set it to your layout -
<?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"
/>
source to share
Expanding to Suvam Roy, I needed to make sure that the child background view that is returned from GetChildView is explicitly assigned either in code or in the associated layout file (whichever technology is used determine the view).
The downside to this is that you lose the default selection of the item. It's easy enough to set a background for the highlighted selector, but I haven't been able to reproduce the fade-out effect yet (even by copying all of the android inline elements into the app).
For reference, the default for most lists (which provides this nice click highlight with a fade out effect) is available
Android.Resource.Drawable.ListSelectorBackground
In the end, just set the cacheColorHint of the ExpandableListView to '# 00000000' (semi-transparent)
source to share