带有垂直线的EditText

时间:2016-02-29 13:21:28

标签: android android-layout

我想创建以下自定义EditText。如何使垂直条像图片上的那个?

enter image description here

2 个答案:

答案 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"/>

答案 1 :(得分: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"/>