How to create a second level second list ExpandableListView?

How to change the second level style of ExpandableListView ? For example, add a background color or a caption \ footer.

Please note that I do not need to set a background for each child. I need to set the style for the whole second level.

Here is an example of what I'm trying to achieve (brown layout is a second level list):

enter image description here

As I said, I do not need to apply a style for each element individually. Because I have a repeating image on the background (not just the color). I know how to apply styles and how to customize them for each child view, but that’s not what I can use to achieve such a background.

EDIT

What I'm trying to achieve:

  • add a shadow at the top of the "Cafe". This is easy to do with ListView , but how to get a ListView in this case? Is there a ListView at all?

  • set the repeating image as the background of the second level (not for each child view separately).

+4
source share
1 answer

One way to achieve this can be as follows.

Create style xml in your res/values/ directory.

Now define style , but you want it. Using this method, it will change all Views where style is applied to that particular style .

Here is my example that I tested:

 <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="backgroundTest" parent="@android:style/TextAppearance.Medium"> <item name="android:background">#00FF00</item> </style> </resources> 

Now add style to your top level layout in xml that defines the children for your ExpandableListView . For example, here is my child (note the style in my LinearLayout ):

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/backgroundTest" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/rightSideTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="25dp" android:paddingLeft="50dp" android:paddingTop="25dp" /> </LinearLayout> 

This should change the color of all your children to green, I believe. You can change style to whatever you want. There is some excellent documentation that I have linked that should help you.

+1
source

All Articles