[英]Android: How to create a customized edittext?
我想知道是否有人可以幫助我設計如下的editText:
請注意,紅色垂直線用於表示必填字段。
我通過布局重新創建了您要查找的內容,它可能與您要找的內容不完全相同。 我嘗試一下,因為我認為它看起來不錯。
創建后的樣子
<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"
...
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.