image - Build Advanced Chat App in Android Studio

Build Advanced Chat App in Android Studio

image - Build Advanced Chat App in Android Studio

In this Blog you will learn the complete process to create and build Advanced chat app (chatting application) in android studio. This Smart and advanced android app for messaging includes login page, colored theme with personal and group chats options.

So, lets start building and coding our advanced chat app without wasting any time.

Step 1:

If you don’t have android studio you can download it here from the given links according to your operating system and requirements.

Download Android Studio from the link given blow according to your operating system Windows, Mac, Linux, Chrome OS etc.

Link:​​ https://developer.android.com/studio

More downloads are available here.​​ 

Link:​​ https://developer.android.com/studio/archive

Step 2:

  • Open android Studio
  • Create project .
  • Select a Project Template window, select Empty Activity and click Next.
  • Enter name of project “LoginPage” .
  • Enter Package name “com.example.loginpage” .
  • select Java Language.
  • Select lowest version of Android your app Minimum SDK.
  • click finish.

Step 3:

Goto the xml file : activity_main.xml in this we can use Drag and Drop to create frontend slide page or we can write the xml code , when you drag and drop use automatically xml code create in background.

following is the activity_main.xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context="com.example.loginpage.MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="User Name"
        android:id="@+id/username"
        android:layout_marginTop="20dp"
        android:textSize="17dp"
        android:inputType="text"
        android:padding="10dp"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:id="@+id/password"
        android:textSize="17dp"
        android:inputType="textPassword"
        android:padding="10dp"
        android:layout_below="@id/username"
        android:layout_marginTop="20dp"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/login"
        android:text="Login"
        android:layout_below="@id/password"
        android:layout_marginTop="20dp"
        android:background="#009688"
        android:textColor="#f5f5f5"
        android:textSize="17dp"
        android:onClick="dothis"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/reset"
        android:text="Reset"
        android:layout_below="@id/login"
        android:layout_marginTop="20dp"
        android:background="#AD1457"
        android:textColor="#f5f5f5"
        android:textSize="17dp"
        android:onClick="dorest"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/reset"
        android:layout_marginTop="40dp"
        android:id="@+id/showerror"
        android:textSize="20dp"
        android:padding="10dp"
        android:textAlignment="center"
        android:textColor="#f5f5f5"/>
</RelativeLayout>

Step: 4

import the package of android files in MainActivity.java :

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

Step 5:

After importing file the write following code for password validation:(continue in MainActivity.java)

public class MainActivity extends AppCompatActivity {

    EditText user, pass;
    Button btn,rest;
    TextView error;

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

        user = (EditText) findViewById(R.id.username);
        pass = (EditText) findViewById(R.id.password);
        btn = (Button) findViewById(R.id.login);
        rest = (Button) findViewById(R.id.reset);
        error = (TextView)findViewById(R.id.showerror);
        error.setVisibility(View.INVISIBLE);
    }

    public void dothis(View v) {
        String u = user.getText().toString();
        String p = pass.getText().toString();
        String check_user = "MAD";  //user name

        String check_pass = "MAD";   //password
if (u.equals("")) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Please enter your email");

        } 
else if (p.equals("")) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Please enter your password");
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);

        }
        else if (!u.equals(check_user) && !p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Invalid Email or Invalid Password");
            user.onEditorAction(EditorInfo.IME_ACTION_DONE);
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
        }
        else if (!u.equals(check_user)) {
            error.setVisibility(View.VISIBLE);
            error.setText("Invalid User");
            error.setBackgroundColor(Color.parseColor("#D50000"));
        }
        else if (!p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Invalid Password");
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
        }
        else if (u.equals(check_user) && p.equals(check_pass)) {
            error.setVisibility(View.VISIBLE);
            error.setBackgroundColor(Color.parseColor("#D50000"));
            error.setText("Login Successfully !!");
            error.setBackgroundColor(Color.parseColor("#00C853"));
            pass.onEditorAction(EditorInfo.IME_ACTION_DONE);
            setTitle("Welcome: " + u);
        }
    }
    public  void dorest(View v){
        user.setText("");
        pass.setText("");
        pass.clearFocus();
    }

Step 6:

launch this activity then show the following output. See in the screenshots below the output of the chat app.

image 2 - Build Advanced Chat App in Android Studio
image 1 - Build Advanced Chat App in Android Studio

Want to make Mobile chat app with pusher see here. Build Mobile Chat App with Pusher in Android Studio

Want to learn how to make more interesting android apps visit here. Android Studio Making & Learning