8 Program to accept username and password from the end user using TextView and EditText in Android Studio.

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.blogspot.codingatharva.manualprograms">



    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />



                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>



</manifest>


MainActivity.java:
package com.blogspot.codingatharva.manualprograms;



import androidx.appcompat.app.AppCompatActivity;



import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {

   EditText user,pass;

    Button b;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        b= findViewById(R.id.btn1);

        user = findViewById(R.id.user);

        pass = findViewById(R.id.pass);



        b.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                if(user.getText().toString().equals("atharva") & pass.getText().toString().equals("1234"))
                {

                    Toast.makeText( getApplicationContext(),"Login Sucessful",Toast.LENGTH_SHORT).show();

                }

                else

                {

                    Toast.makeText( getApplicationContext(),"Login UnSucessful",Toast.LENGTH_SHORT).show();

                }



            }

        });

    }

}


activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <TableLayout 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="50dp" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textSize="25dp" android:text="Login Page" /> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> <TextView android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Enter UserName:" /> <EditText android:id="@+id/user" android:layout_height="wrap_content" android:layout_weight="1" android:hint="abc@gmail.com" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> <TextView android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="Enter Password:" /> <EditText android:id="@+id/pass" android:layout_height="wrap_content" android:layout_weight="1" android:hint="1234" /> </TableRow> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="172dp" android:text="Login" /> </TableLayout>


Output:
Program to accept username and password from the end user using TextView and EditText in Android Studio.

Previous
Next Post »