How to set background to edittext in android?

前端 未结 2 1749
清歌不尽
清歌不尽 2020-12-18 15:28

I am using custom drawable to set background of edit text.Following is the code for edit text background




        
相关标签:
2条回答
  • 2020-12-18 16:11

    I found a solution for these:

    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>
    

    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>
    

    Expected Output:

    enter image description here

    Without using external images we can get a output with the help of drawable text.xml

    0 讨论(0)
  • 2020-12-18 16:24

    Using a drawable this should work :

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
        <solid android:color="#ffffff" />
        <stroke
            android:width="1dp"
            android:color="#555555" />
    </shape> 
    
    0 讨论(0)
提交回复
热议问题