Thursday, August 20, 2015

How to remove underline from EditText in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#dcd9a7"
    >
    <!--
        android:background
            A drawable to use as the background. This can be either a
            reference to a full drawable resource (such as a PNG image,
            9-patch, XML state list description, etc), or a
            solid color such as "#ff000000" (black).

            May be a reference to another resource, in the form
            "@[+][package:]type:name" or to a theme attribute
            in the form "?[package:][type:]name".

            May be a color value, in the form of "#rgb",
            "#argb", "#rrggbb", or "#aarrggbb".

            You can set the EditText background color transparent
            to remove border (underline of EditText) from EditText widget.

            Or, you can remove EditText background by setting the
            android:background attribute value to @null.
    -->
    <EditText
        android:id="@+id/et"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_marginBottom="10dp"
        android:hint="This is first EditText"
        android:fontFamily="sans-serif-light"
        android:background="@null"
        />
    <EditText
        android:id="@+id/et2"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:hint="This is second EditText"
        android:layout_below="@id/et"
        android:background="@android:color/transparent"
        />
</RelativeLayout>
More android examples