如何为EditText添加下划线?

时间:2016-09-27 08:45:09

标签: android android-edittext

如何自定义EditText的下划线,如下所示?

enter image description here

1 个答案:

答案 0 :(得分:4)

你可以做这样的事情

    <EditText
            android:id="@+id/editRemarks"
            android:layout_below="@+id/addNoteRemarks"
            android:gravity="left"
            android:layout_centerHorizontal="true"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@drawable/edit_text_shape"/>

及以下是可绘制文件&#34; edit_text_shape&#34;

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <!-- Draw a 2dp width border around shape -->
        <stroke
            android:color="@color/viewfinder_laser"
            android:width="2dp"
            />
    </shape>
</item>
<!-- Overlap the left, top and right border using background color  -->
<item
    android:bottom="2dp"
    >
    <shape android:shape="rectangle">
        <solid android:color="@color/white"/>
    </shape>
</item>