日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Android?Studio實現登錄界面功能_Android

作者:落幕·重逢 ? 更新時間: 2022-06-21 編程語言

本文實例為大家分享了Android Studio實現登錄界面的具體代碼,供大家參考,具體內容如下

題目

設計一個登錄界面。要求:

a) 包含用戶名、密碼、記住密碼、“忘記密碼”按鈕和“登錄”按鈕。
b) 單擊“忘記密碼”按鈕彈出提示對話框,對話框內容自擬。

答案

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? android:id="@+id/activity_login"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? >
<RelativeLayout
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:focusable="true"
android:focusableInTouchMode="true"
? ? >
<RelativeLayout
? ? android:layout_width="match_parent"
? ? android:layout_height="wrap_content"
? ? android:layout_below="@+id/login_edit_pwd"
? ? android:layout_marginTop="20dp"
? ? android:layout_marginBottom="20dp">
? ? <Button
? ? ? ? android:id="@+id/login_btn_login"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? android:layout_marginTop="52dp"
? ? ? ? android:layout_marginRight="50dp"
? ? ? ? android:background="#545bcb"
? ? ? ? android:text="登錄"
? ? ? ? android:textColor="#ffffff"
? ? ? ? android:textSize="20sp"/>
? ? <Button
? ? ? ? android:id="@+id/login_btn_register"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginLeft="260dp"
? ? ? ? android:layout_marginTop="52dp"
? ? ? ? android:background="#e52525"
? ? ? ? android:text="注冊"
? ? ? ? android:textColor="#ffffff"
? ? ? ? android:textSize="20sp"/>
</RelativeLayout>

<ImageView
? ? android:layout_width="300dp"
? ? android:layout_height="150dp"
? ? android:id="@+id/logo"
? ? android:layout_alignParentRight="true"
? ? android:layout_alignParentEnd="true"
? ? android:layout_alignParentLeft="true"
? ? android:layout_alignParentStart="true"
? ? android:layout_alignParentTop="true"
? ? android:layout_alignWithParentIfMissing="false"
? ? android:background="#ffffff"
? ? android:src="@drawable/user"/>

<EditText
? ? android:layout_width="400dp"
? ? android:layout_height="60dp"
? ? android:inputType="textPassword"
? ? android:ems="10"
? ? android:id="@+id/login_edit_pwd"
? ? android:drawableLeft="@android:drawable/ic_lock_idle_lock"
? ? android:hint="請輸入您的密碼"
? ? android:layout_below="@+id/login_edit_account"
? ? android:layout_alignParentLeft="true"
? ? android:layout_alignParentStart="true"
? ? />

<EditText
? ? android:layout_width="400dp"
? ? android:layout_height="60dp"
? ? android:inputType="textPersonName"
? ? android:id="@+id/login_edit_account"
? ? android:drawableLeft="@android:drawable/ic_menu_myplaces"
? ? android:hint="請輸入您的用戶名"
? ? android:layout_below="@+id/logo"
? ? android:layout_alignParentLeft="true"
? ? android:layout_alignParentStart="true"
? ? android:layout_marginTop="20dp"
? ? />

<LinearLayout
? ? android:orientation="horizontal"
? ? android:layout_width="match_parent"
? ? android:layout_height="wrap_content"
? ? android:layout_below="@+id/login_edit_pwd"
? ? >

? ? <CheckBox
? ? ? ? android:id="@+id/Login_Remember"
? ? ? ? android:layout_width="200dp"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginLeft="10dp"
? ? ? ? android:checked="false"
? ? ? ? android:text="記住密碼"
? ? ? ? android:textSize="15sp"/>
? ? <Button
? ? ? ? android:id="@+id/login_btn_forgetregister"
? ? ? ? android:layout_width="200dp"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginRight="0dp"
? ? ? ? android:backgroundTint="#ffffff"
? ? ? ? android:text="忘記密碼"
? ? ? ? android:textColor="@color/black"
? ? ? ? android:textSize="15sp"/>

</LinearLayout>
</RelativeLayout>
</RelativeLayout>

MainActivity.java:

package com.example.myapplication;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
?import androidx.appcompat.app.AppCompatActivity;
?public class MainActivity extends AppCompatActivity{
? ? ?@Override
? ? ?protected void onCreate(Bundle savedInstanceState){
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? Button button=(Button)findViewById(R.id.login_btn_forgetregister);
? ? ? ? button.setOnClickListener(new View.OnClickListener(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v){new AlertDialog.Builder(MainActivity.this).setTitle("系統提示").setMessage("請輸入驗證信息進行驗證!")
? ? ? ? ? ? ? ? ? ? .setPositiveButton("確定",new DialogInterface.OnClickListener(){
? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog,int which){
? ? ? ? ? ? ? ? ? ? ? ? ? ? finish();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? }).setNegativeButton("返回",new DialogInterface.OnClickListener(){
? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog,int which){
? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? }).show();
? ? ? ? }
? ? ? ? });
? ? ? ? Button button1=(Button)findViewById(R.id.login_btn_login);
? ? ? ? button1.setOnClickListener(new View.OnClickListener(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v){
? ? ? ? ? ? ? ? new AlertDialog.Builder(MainActivity.this).setTitle("系統提示").setMessage("驗證成功!")
? ? ? ? .setNegativeButton("確定",new DialogInterface.OnClickListener(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(DialogInterface dialog,int which){
? ? ? ? }
? ? ? ? }).show();
? ? ? ? }
? ? ? ? });
? ? ? ? Button button2=(Button)findViewById(R.id.login_btn_register);
? ? ? ? button2.setOnClickListener(new View.OnClickListener(){
? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void onClick(View v){
? ? ? ? new AlertDialog.Builder(MainActivity.this).setTitle("系統提示").setMessage("注冊成功!")
? ? ? ? .setNegativeButton("確定",new DialogInterface.OnClickListener(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(DialogInterface dialog,int which){
? ? ? ? }
? ? ? ? }).show();
? ? ? ? }
? ? ? ? });
? ?}
}

運行結果

原文鏈接:https://blog.csdn.net/LOVE_105/article/details/112340934

欄目分類
最近更新