Android?Studio實(shí)現(xiàn)登錄界面功能
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)登錄界面的具體代碼,供大家參考,具體內(nèi)容如下
題目
設(shè)計(jì)一個登錄界面。要求:
a) 包含用戶名、密碼、記住密碼、“忘記密碼”按鈕和“登錄”按鈕。
b) 單擊“忘記密碼”按鈕彈出提示對話框,對話框內(nèi)容自擬。
答案
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("系統(tǒng)提示").setMessage("請輸入驗(yàn)證信息進(jìn)行驗(yàn)證!") ? ? ? ? ? ? ? ? ? ? .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("系統(tǒng)提示").setMessage("驗(yàn)證成功!") ? ? ? ? .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("系統(tǒng)提示").setMessage("注冊成功!") ? ? ? ? .setNegativeButton("確定",new DialogInterface.OnClickListener(){ ? ? ? ? ? ? @Override ? ? ? ? ? ? public void onClick(DialogInterface dialog,int which){ ? ? ? ? } ? ? ? ? }).show(); ? ? ? ? } ? ? ? ? }); ? ?} }
運(yùn)行結(jié)果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Studio實(shí)現(xiàn)簡易登錄界面制作
- Android?studio?利用共享存儲進(jìn)行用戶的注冊和登錄驗(yàn)證功能
- Android Studio實(shí)現(xiàn)登錄功能案例講解
- Android Studio實(shí)現(xiàn)QQ的注冊登錄和好友列表跳轉(zhuǎn)
- Android Studio+Servlet+MySql實(shí)現(xiàn)登錄注冊
- Android Studio連接MySql實(shí)現(xiàn)登錄注冊(附源代碼)
- Android Studio連接SQLite數(shù)據(jù)庫的登錄注冊實(shí)現(xiàn)
- Android Studio實(shí)現(xiàn)簡單的QQ登錄界面的示例代碼
- Android Studio 通過登錄功能介紹SQLite數(shù)據(jù)庫的使用流程
- Android?studio實(shí)現(xiàn)app登錄界面
相關(guān)文章
RecyclerView實(shí)現(xiàn)查看更多及收起
這篇文章主要為大家詳細(xì)介紹了RecyclerView實(shí)現(xiàn)查看更多及收起,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Kotlin開發(fā)中open關(guān)鍵字與類名函數(shù)名和變量名的使用方法淺析
這篇文檔中,我們將解釋如何以及為什么將 open 關(guān)鍵字與類名、函數(shù)名和變量名一起使用,了解內(nèi)部原理是為了幫助我們做擴(kuò)展,同時(shí)也是驗(yàn)證了一個人的學(xué)習(xí)能力,如果你想讓自己的職業(yè)道路更上一層樓,這些底層的東西你是必須要會的2023-02-02Android可循環(huán)顯示圖像的Android Gallery組件用法實(shí)例
這篇文章主要介紹了Android可循環(huán)顯示圖像的Android Gallery組件用法,結(jié)合實(shí)例形式分析了Gallery組件的功能,使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-04-0460條Android開發(fā)注意事項(xiàng)與經(jīng)驗(yàn)總結(jié)
我們在Android App開發(fā)過程中總結(jié)了60條技術(shù)經(jīng)驗(yàn)注意事項(xiàng),大家在開發(fā)過程中一定要注意,下面我們來詳細(xì)說一下這60條經(jīng)驗(yàn)2018-03-03Android使alertDialog.builder不會點(diǎn)擊外面和按返回鍵消失的方法
本篇文章主要介紹了Android使alertDialog.builder不會點(diǎn)擊外面和按返回鍵消失的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-01-01Android使用 Spinner控件實(shí)現(xiàn)下拉框功能
Spinner是android的一種控件,用它我們可以實(shí)現(xiàn)下拉框。下面通過實(shí)例代碼給大家介紹Android使用 Spinner控件實(shí)現(xiàn)下拉框功能,感興趣的朋友一起看看吧2018-08-08