Android 在代码中设置ListSeparatorExtViewStyle

Android 在代码中设置ListSeparatorExtViewStyle,android,Android,在XML中,很容易设置ListSeparatorExtViewStyle: <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Title" android:textSize="16dp" style="?android:attr/listSeparatorTextVie

在XML中,很容易设置
ListSeparatorExtViewStyle

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textSize="16dp"
        style="?android:attr/listSeparatorTextViewStyle"/>


但是如何在java中设置
style
属性呢?

您不能在运行时更改
style
属性。必须在创建视图之前(即在xml中的编译时)设置样式

但是,您可以通过
settextearance
setTextTypeface
在某种程度上实现它

即使这样做没有帮助,下面提到的链接中也解释了解决方法:

如果您只需要一个分隔符,只需在
文本视图下方使用此分隔符即可:

<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/grey"/>


所以不可能在运行时创建ListSeparator吗?@haansn08更新了答案。看一看这肯定会解决你的问题。