1

我是新手用android布局,所以我需要一些帮助。android上的自定义editText

我想创建一个自定义EDITTEXT,这样的事情:

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

我想解决这个问题最好的可能的方式。

有人?

谢谢。

+0

这已经存在。检查[this](http://android-developers.blogspot.com/2015/05/android-design-support-library.html)并查找MaterialEditText。 –

回答

2

如果你想在左边的蓝线,你可以只设置上的EditText的背景,比如,

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

然后在你的绘制文件夹中创建另一个文件这就是所谓的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> 

而最终选择文件 - custom_edittext.xm

<selector 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:drawable="@drawable/custom_layer">   
    </item> 
</selector> 
+0

谢谢,你帮了我很多。 –

1

U可以创建一个Shape绘制并设置形状绘制为的EditText背景