Custom editText on android

醉酒当歌 提交于 2020-01-05 12:09:45

问题


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

I want create a custom editText, something like this:

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

Someone?

Thanks.


回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/30940725/custom-edittext-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!