Saturday, 20 August 2016

Floating Lables EditText example in Android





build.gradle(Module: app) :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.chantisandroid.floatinglables"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'   //you can add this line
}


activity_main.xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="60dp"
        android:layout_alignParentTop="true">


        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:hint="Full Name" />


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


        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:hint="Phone" />


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

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Password" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/layout_repassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText_repassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:hint="Confirm Password" />
        </android.support.design.widget.TextInputLayout>

        <Button android:id="@+id/button_signup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Sign Up"
            android:background="@color/colorPrimary"
            android:layout_marginTop="40dp"
            android:textColor="#ffffff"/>

    </LinearLayout>

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


MainActivity.java:

package com.chantisandroid.floatinglables;

import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    EditText Name,phone, Email, Password,repassword;
    TextInputLayout LayoutName,LayoutPhone ,LayoutEmail, LayoutPassword ,LayoutRepassword;
    Button SignUp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LayoutName = (TextInputLayout) findViewById(R.id.layout_name);
        LayoutPhone = (TextInputLayout) findViewById(R.id.layout_phone);
        LayoutEmail = (TextInputLayout) findViewById(R.id.layout_email);
        LayoutPassword = (TextInputLayout) findViewById(R.id.layout_password);
        LayoutRepassword = (TextInputLayout) findViewById(R.id.layout_repassword);

        Name = (EditText) findViewById(R.id.editText_name);
        phone = (EditText) findViewById(R.id.editText_phone);
        Email = (EditText) findViewById(R.id.editText_email);
        Password = (EditText) findViewById(R.id.editText_password);
        repassword = (EditText) findViewById(R.id.editText_repassword);

        SignUp = (Button) findViewById(R.id.button_signup);
        SignUp.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

    }
}


No comments:

Post a Comment

Alarm Manager Example in Android