2012-07-22 69 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