Android TextInput Layout
TextInputLayout (Android Material Design ) is used to control over the visual aspects of any text input. TextInputLayout widget is included in the Design Support Library . For create TextInputLayout in android material design you have to import two libraries in project. First one is appcompace-v7 and second one is design support library . Follow the bellow steps for create TextInputLayout in Android.
Step 1: Create Project
a) Open Android Studio
b) Go to File >New> New Project > Project Name > Next > Next > Next > Finish
Step 2: Add Design Library
Open build.gradle > add this line com.android.support:design:22.2.0'
> Sync the gradle file . Like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
If Gradle doesn’t automatically ask you to sync your project, open module 'app' from the Build menu or press F9. By doing so, the Android Studio build system will automatically fetch the necessary resources and you will be able to import any required classes.
Step 3 : Layout Design
open activity_main.xml file and add the bellow code
<?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:background="@drawable/shape_white_border">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:textColor="@color/white"
android:text="Add New Contact Details"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="5dp"
android:background="@drawable/shape_white_border">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColorHint="#000000">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_white_border"
android:hint="Name"
android:inputType="textAutoComplete|textAutoCorrect|textCapWords"
android:paddingLeft="10dp"
android:minHeight="40dp" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColorHint="#000000">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_white_border"
android:hint="Phone"
android:inputType="number"
android:paddingLeft="10dp"
android:minHeight="40dp" />
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="8dp"
android:background="@drawable/shape_white_border"
android:textColor="#FFFFFF"
android:text="Save"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Step 4: Create shape file with name "shape_white_border.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#009999" >
</solid>
<stroke
android:width="0.5dp"
android:color="#FFFFFF" >
</stroke>
</shape>
Find Us :
Facebook : @apnaandroid
Google+ : Apna Java
Youtube : Android & Java Tutorial
Comments
Post a Comment