【发布时间】:2015-04-13 21:15:01
【问题描述】:
我想知道是否有人可以帮助我设计如下的editText:
注意红色竖线表示必填字段。
【问题讨论】:
-
只需在 EditText 的右侧添加一个视图,将宽度设置为 2dp,并将背景设置为您想要的任何颜色(在本例中为 android:color/red)
标签: android android-layout android-edittext android-xml
我想知道是否有人可以帮助我设计如下的editText:
注意红色竖线表示必填字段。
【问题讨论】:
标签: android android-layout android-edittext android-xml
我通过布局重新创建了您正在寻找的内容,它可能不是您正在寻找的内容。我试了一下,因为我觉得它看起来不错。
这是创建时的样子
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="#d2d2d2">
<EditText
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_margin="1dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:background="#fff"
android:textColor="#6d6d6d"/>
<view
android:layout_width="1dp"
android:layout_height="56dp"
android:layout_alignParentRight="true"
android:background="@android:color/holo_red_dark"/>
</RelativeLayout>
【讨论】:
你可以使用选择器。
例如:
在 res-->drawable 文件夹中创建另一个名为“custom_edittext.xml”的 xml 文件并粘贴以下代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image_edittext_focused" android:state_focused="true"/>
<item android:drawable="@drawable/image_edittext_normal"/>
</selector>
最后在你的editText中调用custom_edittext.xml作为背景
<EditText
...
android:background="@drawable/custom_edittext"
...
/>
【讨论】: