Customizing EditText on Android

1

I have seen that there are several ways to customize a EditText , one is in background and the other is XML .

What would be the best option? Is it disadvantageous to use background or does it work?

    
asked by anonymous 13.03.2018 / 04:20

1 answer

1

The best way to customize or style a EditText , just like any other view , is to create a dedicated xml file.

A file dedicated to customization ensures:

  • Reuse;
  • Organization;
  • Easy access;

For example, I want to create a editText with curved / rounded edges.

First I'll create an xml file where I'll put all the style attributes: rounded_edittext.xml

 <shape xmlns:android="http://schemas.android.com/apk/res/android" >

        <solid android:color="#FFFFFF" />

        <stroke
            android:width="1dp"
            android:color="#862f99" />
        <corners
            android:topLeftRadius="10dp"
            android:topRightRadius="10dp"
            android:bottomLeftRadius="10dp"
            android:bottomRightRadius="10dp"/>
    </shape>

Now I can add the style to my editText set background as follows:

   <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_edittext"
        android:ems="10"
        android:inputType="textPersonName"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="135dp" />

And now it's'

Moreinfo: link

    
13.03.2018 / 22:59