2016-02-29 140 views
0

我想創建下面的自定義EditText。如何使垂直條像圖片上的那樣?垂直線的EditText

enter image description here

+0

你可以使用背景或左繪製爲 –

回答

2

風格edittext_custom_style.xml:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#75d0e2" /> 
    </shape> 
</item> 
<item android:left="5dp"> 
    <shape android:shape="rectangle"> 
     <solid android:color="#FFFFFF" /> 
    </shape> 
</item> 
</layer-list> 

XML:

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/edittext_custom_style"/> 
0
Create same bar drawable and assign drawableLeft to edittext 
Code put image in respective drawables like drawable-xhdpi etc 
Sample is here. 
<EditText 
       android:id="@+id/password" 
       style="@style/inputFieldStyle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:drawableLeft="@drawable/password_icon" 
       android:hint="@string/password_hint" 
       android:imeOptions="actionDone" 
       android:inputType="textPassword" 
       android:maxLines="1"/> 
+0

請發佈代碼示例更清晰。如果您向提問者展示如何操作,它只是有用的答案...... – Opiatefuchs