0% found this document useful (0 votes)
18 views3 pages

Exp No7

The document contains an Android application code with an XML layout for a login screen, including TextViews for username and password, EditTexts for user input, and a Login button. The Java file defines the MainActivity class, which handles user input and displays Toast messages based on the login status. Additionally, the manifest file outlines application settings and the main activity configuration.

Uploaded by

nikantgorle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Exp No7

The document contains an Android application code with an XML layout for a login screen, including TextViews for username and password, EditTexts for user input, and a Login button. The Java file defines the MainActivity class, which handles user input and displays Toast messages based on the login status. Additionally, the manifest file outlines application settings and the main activity configuration.

Uploaded by

nikantgorle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXP NO.

XML file

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserName"
android:id="@+id/text1"
android:textSize="20sp"
android:textStyle="bold|normal"
/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/text1"
android:hint="Enter Your Username"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:id="@+id/text2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_below="@id/text1"
android:layout_marginTop="20dp"
android:id="@+id/text3"
android:textSize="20sp"
android:textStyle="bold|normal"
/>

<EditText
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text2"
android:layout_marginLeft="110dp"
android:layout_marginTop="2dp"
android:textSize="20sp"
android:hint="Enter Your Password" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@id/text3"
android:layout_marginTop="20dp"
android:id="@+id/btn1"/>
</RelativeLayout>

JAVA File

package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {


Button login;
EditText username, password;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
username=(EditText) findViewById(R.id.text2);
password=(EditText) findViewById(R.id.text4);
login=(Button) findViewById(R.id.btn1);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(username.getText().toString().isEmpty()||
password.getText().toString().isEmpty()){
Toast.makeText(getApplicationContext(), "userNAme and Password
Required", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "user Login Successfully",
Toast.LENGTH_SHORT).show();
}
}
});
}
}

MANIFEST FILE:

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


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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

Output:

You might also like