MAD Practical 28
MAD Practical 28
MAD Practical 28
Roll No: 3
android:layout_width="match_parent"
Q28)
activity_main.xml
android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_below="@id/textView"
xmlns:android="http://schemas.android.c
om/apk/res/android" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
xmlns:tools="http://schemas.android.com
android:layout_marginTop="50dp"
/tools"
android:background="#ECECEC"
android:layout_width="match_parent"
android:ems="10"
android:layout_height="match_parent"
android:hint="Username"
tools:context=".MainActivity">
android:inputType="textPersonName"
<TextView
android:padding="12dp" />
android:id="@+id/textView"
<EditText
android:layout_width="wrap_content"
android:id="@+id/edt2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_below="@id/edt1"
android:fontFamily="sans-serif-
condensed-light" android:layout_marginStart="20dp"
android:text="LOGIN" android:layout_marginEnd="20dp"
android:textColor="#273898" android:layout_marginTop="20dp"
android:textSize="30sp" android:background="#ECECEC"
<EditText android:inputType="textPassword"
android:padding="12dp" /> </RelativeLayout>
MainActivity.java
<Button package com.example.practicaal;
android:id="@+id/button"
android:layout_width="140dp" import
androidx.appcompat.app.AppCompatActiv
android:layout_height="wrap_content" ity;
android:layout_below="@id/edt2"
import android.os.Bundle;
android:layout_centerHorizontal="true" import android.view.View;
android:layout_marginTop="30dp" import android.widget.Button;
android:backgroundTint="#03A9F4" import android.widget.EditText;
android:onClick="formLogin" import android.widget.TextView;
android:text="Login" import android.widget.Toast;
android:textColor="#FFFFFF"
android:textSize="16sp" public class MainActivity extends
AppCompatActivity {
android:textStyle="bold" />
EditText ed1,
<TextView
ed2; TextView tv;
android:id="@+id/textView2"
Button b1;
android:layout_width="wrap_content" int count;
android:layout_height="wrap_content"
@Override
android:layout_below="@id/button"
protected void
onCreate(Bundle
android:layout_centerHorizontal="true" savedInstanceState) {
android:layout_marginTop="30dp" super.onCreate(savedInstanceState);
android:textColor="#000000"
android:textSize="20sp" /> setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.edt1);
ed2 = findViewById(R.id.edt2); tv.setText("");
tv = findViewById(R.id.textView2); }
b1 = findViewById(R.id.button); }
}
count = 3; Output:
tv.setText("You have only " + count +
" Attempts");
}