Custom designing EditText

前端 未结 6 865
傲寒
傲寒 2020-11-29 17:29

I have custom designed EditText

\"enter

search_page.xml<

相关标签:
6条回答
  • 2020-11-29 17:55

    Use a 9-patch drawable or create a Shape drawable.

    0 讨论(0)
  • 2020-11-29 17:59
    android:background="#E1E1E1" 
    // background add in layout
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ffffff">
    </EditText>
    
    0 讨论(0)
  • 2020-11-29 18:02

    Use the below code in your rounded_edittext.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <solid android:color="#FFFFFF" />
    
        <stroke
            android:width="1dp"
            android:color="#2f6699" />
        <corners 
            android:radius="10dp"            
            />
    
    </shape>
    

    This should work

    0 讨论(0)
  • 2020-11-29 18:05

    Use the below code in your rounded_edittext.xml :

    <?xml version="1.0" encoding="utf-8" ?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:thickness="0dp"
           android:shape="rectangle">
    
        <stroke android:width="2dp"
                android:color="#2F6699"/>
    
        <corners android:radius="3dp" />
    
        <gradient   android:startColor="#C8C8C8"
                    android:endColor="#FFFFFF"
                    android:type="linear"
                    android:angle="270"/>
    </shape>
    

    0 讨论(0)
  • 2020-11-29 18:10

    enter image description here

    For EditText in image above, You have to create two xml files in res-->drawable folder. First will be "bg_edittext_focused.xml" paste the lines of code in it

    <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" >
            <solid android:color="#FFFFFF" />
            <stroke
                android:width="2dip"
                android:color="#F6F6F6" />
            <corners android:radius="2dip" />
            <padding
                android:bottom="7dip"
                android:left="7dip"
                android:right="7dip"
                android:top="7dip" />
        </shape>
    

    Second file will be "bg_edittext_normal.xml" paste the lines of code in it

    <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android" >
            <solid android:color="#F6F6F6" />
            <stroke
                android:width="2dip"
                android:color="#F6F6F6" />
            <corners android:radius="2dip" />
            <padding
                android:bottom="7dip"
                android:left="7dip"
                android:right="7dip"
                android:top="7dip" />
        </shape>
    

    In res-->drawable folder create another xml file with name "bg_edittext.xml" that will call above mentioned code. paste the following lines of code below in bg_edittext.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/bg_edittext_focused" android:state_focused="true"/>
        <item android:drawable="@drawable/bg_edittext_normal"/>
    </selector>
    

    Finally in res-->layout-->example.xml file in your case wherever you created your editText you'll call bg_edittext.xml as background

       <EditText
        :::::
        :::::  
        android:background="@drawable/bg_edittext"
        :::::
        :::::
        />
    
    0 讨论(0)
  • 2020-11-29 18:19

    edit_text.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#ffffff" />
        <corners android:radius="5dp"/>
        <stroke android:width="2dip" android:color="@color/button_color_submit" />
    </shape>
    

    use here

    <EditText
     -----
     ------
     android:background="@drawable/edit_text.xml"
    />
    
    0 讨论(0)
提交回复
热议问题