Android文本视图布局问题

Android文本视图布局问题,android,layout,Android,Layout,我需要一些关于textview样式的帮助。我需要带下划线的文本视图。我制作了一些布局XML。但我不能取得任何成功。 我想让这一行与底线保持一致。这里是我的xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:left="2dp"

我需要一些关于textview样式的帮助。我需要带下划线的文本视图。我制作了一些布局XML。但我不能取得任何成功。 我想让这一行与底线保持一致。这里是我的xml

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
   <item
        android:left="2dp"
        android:right="10dp"
        android:top="20dp">
        <shape android:shape="line" >
            <stroke
                android:width="1dp"
                android:color="@color/colorPrimary"/>

            <padding
                android:bottom="0dp"
                android:left="5dp"
                android:right="5dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>


如何操作。

将drawable设置为Textview的背景:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/holo_red_dark" />

    </shape>
</item>

<item android:bottom="2dp">
    <shape android:shape="rectangle">
        <solid android:color="#ffffff" />
    </shape>
</item>

</layer-list>

将drawable设置为文本视图的背景:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/holo_red_dark" />

    </shape>
</item>

<item android:bottom="2dp">
    <shape android:shape="rectangle">
        <solid android:color="#ffffff" />
    </shape>
</item>

</layer-list>

检查此帖子检查此帖子