2012-07-22 66 views
4

如何更改ExpandableListView的二级清单样式?例如,添加背景颜色或页眉\页脚视图。如何设置ExpandableListView的二级列表?

请注意,我不需要设置背景每个孩子。我需要为整个第二级别设置样式。

这里是我想要达到一个例子(棕色布局 - 是第二级列表):

enter image description here

正如我所说,我并不需要应用样式的每个项目个别。因为我在背景有一个可重复的图像(不只是颜色)。我知道如何应用样式以及如何将其设置到每个子视图,但这不是我可以用来实现这样的背景的。

编辑

我想要实现:

  1. 在 “在咖啡馆” 顶部添加阴影。这可以用ListView轻松完成,但在这种情况下如何获得ListView?有没有ListView

  2. 设置可重复的图像作为背景第二级列表(不是针对每个子视图单独)。

+0

'android:style =“@ style/mysubStyle”'? – Ronnie 2012-07-22 12:21:39

+0

@ userSeven7s我应该在哪里应用这种风格?如果我将它应用于ExpandableListView本身,那么我假设整个样式将被改变(包括第一和第二级)。我只需要风格第二级。 – 2012-07-22 12:37:56

+0

你必须申请每个子级别的项目..当添加getview方法.. – Ronnie 2012-07-22 12:39:24

回答

1

这样可以实现的一个方法是以下几点。

在您的res/values/目录中创建一个stylexml

现在定义你的style然而你想要它。以这种方式使用时,它将更改所有Views,其中style应用于此特定style

这是我的例子,我有测试:

<?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> 

现在添加style到您的顶层布局定义儿童为您ExpandableListView的XML。例如,这里是我的孩子(注意我LinearLayoutstyle):

<?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> 

这应该改变所有你的孩子绿色的颜色,我相信。您可以将style更改为任何您想要的。有一些很好的文档可以帮助你。

+0

正如我所说的,我不需要为每个项目分别应用样式。因为我在背景有一个可重复的图像(不只是颜色)。我知道如何应用样式以及如何将其设置到每个子视图,但这不是我可以用来实现这样的背景的。 – 2012-07-28 13:17:57

+0

从你的问题中很难理解你的确切目标。看看你能否澄清一点。谢谢 – prolink007 2012-07-28 16:34:24

+0

更新了我的问题。谢谢你的回答:) – 2012-07-28 18:14:30