ExpandableListView的樣式如何設(shè)置

小樊
81
2024-10-14 13:34:57

要設(shè)置ExpandableListView的樣式,您需要遵循以下步驟:

  1. res/values目錄下創(chuàng)建或修改styles.xml文件。

  2. styles.xml文件中,定義一個(gè)新的樣式,繼承自Base.Theme.AppCompat或其他適用的主題。在這個(gè)樣式中,您可以設(shè)置ExpandableListView的屬性,例如背景顏色、文本顏色、分隔線顏色等。

<resources>
    <style name="MyExpandableListViewStyle" parent="Base.Theme.AppCompat">
        <!-- 設(shè)置背景顏色 -->
        <item name="android:background">@color/list_background</item>
        <!-- 設(shè)置文字顏色 -->
        <item name="android:textColor">@color/list_text_color</item>
        <!-- 設(shè)置分隔線顏色 -->
        <item name="android:divider">@color/list_divider</item>
        <!-- 設(shè)置分隔線高度 -->
        <item name="android:dividerHeight">1dp</item>
    </style>
</resources>
  1. 在您的ExpandableListView控件中,將定義的樣式應(yīng)用到android:theme屬性。
<ExpandableListView
    android:id="@+id/expandable_list_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyExpandableListViewStyle" />

現(xiàn)在,ExpandableListView將采用您在styles.xml中定義的樣式。請(qǐng)注意,您可以根據(jù)需要自定義樣式屬性。

0