Custom editText on android

2019-08-01 08:11发布

I'm newbie with android layout, so i need some help.

I want create a custom editText, something like this:

An email field with this blue "bar" in the left side

I'm want to fix that with the best possible way.

Someone?

Thanks.

2条回答
Juvenile、少年°
2楼-- · 2019-08-01 08:32

If you want the blue line on the left, you can just set the background on the EditText, such as,

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="@drawable/custom_edittext"
        android:layout_weight="1" />

Then create another file in your drawable folder this is called custom_layer.xml

   <?xml version="1.0" encoding="utf-8"?>
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="-5dp"
        android:right="-5dp"
        android:top="-5dp">
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_of_the_background" />
            <stroke
                android:width="5dp"
                android:color="@color/color_of_the_border" />
        </shape>
    </item>
</layer-list>

And a final selector file - custom_edittext.xm.

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/custom_layer">        
    </item>
</selector>
查看更多
甜甜的少女心
3楼-- · 2019-08-01 08:42

U can create a Shape drawable and set shape drawable as the EditText background

查看更多
登录 后发表回答