Skip to main content

Android Material Text Input

Here i have a beginners tutorial for Android Material Text Input.

This gives better user experience than the traditional EditText with moving Text Hint which automatically moves and shrinks to up when the text is filled or the input is Focused.

Follow the step by step tutorial .

Step 1 : Add Dependancies

You need to add Android Design Library  and appcompat Library to your android project ( build.Gradle In App Folder) in order to use the material TextInput.

 

dependencies {    
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
}

* Then Sync the Project

Step 2 : Add TextInput in XML Layout

You can Simply add your EditText Inside the android.support.design.widget.TextInputLayout node

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/edittext1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="EditText"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:singleLine="true" />

</android.support.design.widget.TextInputLayout>

Step 3 : Getting Value in Activity Class

You can simply get the text from the edittext in the traditional way by getText()

EditText edit = (EditText)findViewById(R.id.editext1);
String result = edit.getText().toString();