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背景