温馨提示×

ExpandableListView的样式如何设置

小樊
81
2024-10-14 13:34:57
栏目: 编程语言

要设置ExpandableListView的样式,您需要遵循以下步骤:

  1. res/values目录下创建或修改styles.xml文件。

  2. styles.xml文件中,定义一个新的样式,继承自Base.Theme.AppCompat或其他适用的主题。在这个样式中,您可以设置ExpandableListView的属性,例如背景颜色、文本颜色、分隔线颜色等。

<resources>
    <style name="MyExpandableListViewStyle" parent="Base.Theme.AppCompat">
        <!-- 设置背景颜色 -->
        <item name="android:background">@color/list_background</item>
        <!-- 设置文字颜色 -->
        <item name="android:textColor">@color/list_text_color</item>
        <!-- 设置分隔线颜色 -->
        <item name="android:divider">@color/list_divider</item>
        <!-- 设置分隔线高度 -->
        <item name="android:dividerHeight">1dp</item>
    </style>
</resources>
  1. 在您的ExpandableListView控件中,将定义的样式应用到android:theme属性。
<ExpandableListView
    android:id="@+id/expandable_list_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyExpandableListViewStyle" />

现在,ExpandableListView将采用您在styles.xml中定义的样式。请注意,您可以根据需要自定义样式属性。

0