[英]How to make a “L” shaped edit text drawable selector in android
我正在嘗試如下創建一個EditText
題:
您需要使用<layer-list>
完成所需的操作。 取自這個答案
RES /繪制/ text.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="#000000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:bottom="3px" android:left="3px">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
RES /布局/ activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:background="@drawable/text"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
android:ems="10"
android:gravity="center_horizontal"
android:padding="2dp"
android:password="true" />
</RelativeLayout>
預期產量:
這會工作
布局
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:ems="10" android:layout_margin="5dp" android:paddingLeft="5dp" android:hint="Email" android:background="@drawable/test_edit" android:id="@+id/editText" />
Layer_list
<item android:drawable="@color/lightBlue"/> <item android:drawable="@color/darkBlue" android:left="2dp" android:bottom="2dp" />
顏色
darkBlue #ff1ca9ff lightBlue #ffb6f1ff
不知道這是否對您有幫助,但我只是通過xml創建並使用Android 4.4主題將其設置為L形。 然后,我將背景色設置為藍色。 這是怎么做的:
創建color.xml
文件,以輸入所需的顏色值。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dodgerblue">#1E90FF</color>
<color name="lightskyblue_1">#B0E2FF</color>
</resources>
然后,在您的EditText中,如下設置顏色
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
android:textColor="@color/lightskyblue_1"
android:background="@color/dodgerblue"
/>
如果您需要更多顏色, 這是一個有用的鏈接。 希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.