欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Studio實(shí)現(xiàn)登錄功能案例講解

 更新時(shí)間:2021年08月02日 10:16:39   作者:huangyixian2  
這篇文章主要介紹了Android Studio實(shí)現(xiàn)登錄功能案例講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
LoginActivity.java
 
包 com.hyx.example.mymap;
 
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
 
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
 
 
公共類 LoginActivity擴(kuò)展 Activity {
     private EditText username = null ;
    private EditText password = null ;
    private Button login = null ;
    private SharedPreferences sharedPreferences ;
 
    //初始化控件
 公共無效的init(){
        用戶名 =(的EditText)findViewById(R.id。 username_edit);
        密碼 =(的EditText)findViewById(R.id。 userpassword_edit);
        login =(Button)findViewById( R.id.login_button);    
 
 
    }
 
    @Override
 protected void onCreate(Bundle savedInstanceState){
         super .onCreate(savedInstanceState);    
        的setContentView(R.layout 登錄); //顯示自己的UI視圖
 //        初始化控件
 init();
//調(diào)用驗(yàn)證是否第一次登錄方法
         userUpdate();
//調(diào)用登錄驗(yàn)證方法
         loginVerify();
 
 
    }
 
    //判斷是否第一次登錄初始化用戶名密碼
 public void userUpdate(){
 //讀取文件內(nèi)容
 sharedPreferences = getSharedPreferences( “myfile”, MODE_PRIVATE);
//讀取數(shù)據(jù)
 String susername = sharedPreferences .getString( “username”, “”);                    
        String spwd = sharedPreferences .getString(“pwd”,“”);
//第一次進(jìn)入程序讀取用戶名密碼為空,則寫入初始化數(shù)據(jù)并提示用戶
 if(susername.equals(“”)&& spwd.equals(“”)){        
 
//寫入數(shù)據(jù)
             SharedPreferences.Editor editor = sharedPreferences .edit();
            editor.putString(“username”,“admin”);
            editor.putString(“pwd”,“123456”);
//提交數(shù)據(jù)
             editor.commit();
            吐司。makeText(LoginActivity。這個(gè),“初始化用戶名管理員密碼123456” ,
                    吐司。LENGTH_LONG)。show();
        }
    }
 
 
    //登錄驗(yàn)證
 public void loginVerify(){    
 
 
//點(diǎn)擊登錄按鈕所發(fā)生的事件。(1,驗(yàn)證合法2,驗(yàn)證不合法)
 login .setOnClickListener( new OnClickListener(){        
 
 
            @Override
 public void onClick(查看arg0){
 //定義變量
 String strUsername,strPassword;
//得到輸入框內(nèi)容
 strUsername = username .getText()。toString();                                            
                strPassword = password .getText()。toString();
 
//讀取文件內(nèi)容得到用戶名密碼
 sharedPreferences = getSharedPreferences( “myfile”, MODE_PRIVATE);
//讀取數(shù)據(jù)
 String susername = sharedPreferences .getString( “username”, “”);                                
                String spwd = sharedPreferences .getString(“pwd”,“”);
 
 
 
//登錄校驗(yàn)
 if(strUsername.equals(susername)&& strPassword.equals(spwd)){
 //登錄成功后提示
 Toast。makeText(LoginActivity。這個(gè), “登陸成功!” ,                                    
                            吐司。LENGTH_SHORT).show();
//登陸成功后切換到MainActivity.class
                    意圖意圖= 新意圖(LoginActivity。此,
                            主要活動(dòng)。課程);
//啟動(dòng)
                     startActivity(intent);
 
//登錄成功后銷毀登錄界面
                     finish();
                } else {
                    吐司。makeText(LoginActivity。這個(gè),“登陸失?。 ?,
                            吐司。LENGTH_SHORT).show();
                }
 
            }
        });
    }
 
 
// @Override
 // public boolean onCreateOptionsMenu(菜單菜單){
 // getMenuInflater()。inflate(R.menu.main,menu);
//返回true;
//}
 
 }
 
login.xml
< RelativeLayout xmlns:android = “http://schemas.android.com/apk/res/android”
 xmlns:custom = “http://schemas.android.com/apk/res-auto”
 android :layout_width = “match_parent “
 android :layout_height = ”match_parent“
 android :fitsSystemWindows = ”true“ >                
 
    < RelativeLayout
 android :id = “@ + id / login_layout”
 android :layout_width = “match_parent”
 android :layout_height = “wrap_content”
 android :layout_marginLeft = “20dp”
 android :layout_marginRight = “20dp”
 android :gravity = “center” >                                                
        < FrameLayout
 android :id = “@ + id / username_layout”
 android :layout_width = “fill_parent”
 android :layout_height = “wrap_content”
 android :layout_marginTop = “55dp”
 android :gravity = “center” >                                                            
            < EditText
 android :id = “@ + id / username_edit”
 android :layout_width = “match_parent”
 android :layout_height = “55dp”
 android :layout_marginTop = “5dp”
 android :hint = “賬號(hào)/手機(jī)號(hào)/郵箱”
 android :paddingRight = “60dp”
 android :maxLength = “20”
 android :paddingLeft = “55dp” >                                                                                                                                
            </ EditText >
            < ImageView
 android :layout_width = “22dp”
 android :layout_height = “21dp”
 android :layout_marginStart = “8dp”
 android :layout_gravity = “l(fā)eft | center_vertical”
 android :background = “@ drawable / zhanghao”
 android :visibility = “visible” / >                                                                                                
            < TextView
 android :id = “@ + id / contry_sn”
 android :layout_width = “40dp”
 android :layout_height = “50dp”
 android :layout_gravity = “l(fā)eft | center_vertical”
 android :layout_marginTop = “4dp”
 android :gravity = “center”
 android :text = “+ 62” android :textColor = “@
 android :color / black”
 android :textSize = “18sp”
 android :visibility = “invisible” />                                                                                                                                                                
        </ FrameLayout >
        < FrameLayout
 android :id = “@ + id / usercode_layout”
 android :layout_width = “fill_parent”
 android :layout_height = “wrap_content”
 android :layout_below = “@ id / username_layout”
 android :layout_marginTop = “6dp”
 android :gravity = “center “ >                                                                        
            < EditText
 android :id = “@ + id / userpassword_edit”
 android :layout_width = “match_parent”
 android :layout_height = “55dp”
 android :hint = “密碼”
 android :inputType = “textPassword”
 android :paddingRight = “60dp”
 android : maxLength = “20”
 android :paddingLeft = “55dp” >                                                                                                                                
            </ EditText >
 
            < ImageView
 android :layout_width = “24dp”
 android :layout_height = “22dp”
 android :layout_marginStart = “7dp”
 android :layout_gravity = “l(fā)eft | center_vertical”
 android :background = “@ drawable / mima” />                                                                                
            < 按鈕
 android :id = “@ + id / passwordeye”
 android :layout_width = “23dp”
 android :layout_height = “23dp”
 android :background = “@ drawable / kejian”
 android :layout_gravity = “right | center_vertical”
 android :layout_marginRight = “10dp”
 />                                                                                                                
 
 
        </ FrameLayout >
 
        < Button
 android :id = “@ + id / login_button”
 android :layout_width = “wrap_content”
 android :layout_height = “45dp”
 android :layout_below = “@ + id / usercode_layout”
 android :layout_centerHorizo​​ntal = “true”
 android :layout_marginTop = “ 34dp“
 android :background = ”@ drawable / bluebutton“
 android :textSize = ”18sp“ android :text = ” 登錄
 “
 android :textColor = ”#fffffff“ />                                                                                                                        
        < Button
 android :id = “@ + id / login_error”
 android :layout_width = “wrap_content”
 android :layout_height = “wrap_content”
 android :layout_alignRight = “@ id / login_button”
 android :layout_below = “@ id / login_button”
 android :text = “忘記密碼”
 android :background = “#00000000”
 android :textSize = “16sp” />                                                                                                
        < Button
 android :id = “@ + id / register”
 android :layout_width = “wrap_content”
 android :layout_height = “wrap_content”
 android :layout_alignLeft = “@ id / login_button”
 android :layout_below = “@ id / login_button”
 android :background = “#00000000”
 android :gravity = “l(fā)eft | center_vertical”
 android :text = “注冊(cè)”
 android :textSize = “16sp”
 android :visibility = “visible” />                                                                                                                        
    </ RelativeLayout >
    < RelativeLayout
 android :id = “@ + id / remember_layout000”
 android :layout_width = “wrap_content”
 android :layout_height = “wrap_content”
 android :layout_alignParentBottom = “true”
 android :layout_marginBottom = “1dp”
 android :layout_marginLeft = “20dp”
 android : layout_marginRight = “20dp” >                                                        
 
    </ RelativeLayout >
</ RelativeLayout >

注意:一定要在AndroidManifest.xml里加activity啊?。?!

到此這篇關(guān)于Android Studio實(shí)現(xiàn)登錄功能案例講解的文章就介紹到這了,更多相關(guān)Android Studio實(shí)現(xiàn)登錄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android開發(fā)準(zhǔn)確獲取手機(jī)IP地址的兩種方式

    Android開發(fā)準(zhǔn)確獲取手機(jī)IP地址的兩種方式

    這篇文章主要介紹了Android開發(fā)準(zhǔn)確獲取手機(jī)IP地址的兩種方式,需要的朋友可以參考下
    2020-03-03
  • Android PopupWindow用法解析

    Android PopupWindow用法解析

    這篇文章主要為大家詳細(xì)解析了Android PopupWindow用法,對(duì)PopupWindow源碼進(jìn)行分析,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android資源命名規(guī)范 分享

    Android資源命名規(guī)范 分享

    Android資源命名規(guī)范 分享,需要的朋友可以參考一下
    2013-06-06
  • Android混合開發(fā)教程之WebView的使用方法總結(jié)

    Android混合開發(fā)教程之WebView的使用方法總結(jié)

    WebView是一個(gè)基于webkit引擎、展現(xiàn)web頁(yè)面的控件,下面這篇文章主要給大家介紹了關(guān)于Android混合開發(fā)教程之WebView的使用方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧
    2018-05-05
  • Android  TimerTask 的簡(jiǎn)單應(yīng)用及注意事項(xiàng)

    Android TimerTask 的簡(jiǎn)單應(yīng)用及注意事項(xiàng)

    這篇文章主要介紹了Android TimerTask 的簡(jiǎn)單應(yīng)用及注意事項(xiàng)的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Android使用硬件加速的方式

    Android使用硬件加速的方式

    硬件加速是指利用設(shè)備的硬件資源來加速圖形渲染和圖像處理等操作,以提高應(yīng)用程序的性能和用戶體驗(yàn),Android使用硬件加速的目的是為了提高圖形渲染的性能和效果,本文給大家詳細(xì)介紹了Android如何使用硬件加速,需要的朋友可以參考下
    2023-10-10
  • 詳解Android通知欄沉浸式/透明化完整解決方案

    詳解Android通知欄沉浸式/透明化完整解決方案

    這篇文章主要介紹了詳解Android通知欄沉浸式/透明化完整解決方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • Android開發(fā)之Activity詳解

    Android開發(fā)之Activity詳解

    本文是翻譯的官方文檔的內(nèi)容,看起來可能會(huì)有些生硬,但是內(nèi)容很有用,給大家一個(gè)參考,希望對(duì)大家學(xué)習(xí)有所幫助。
    2016-06-06
  • 使用RecyclerView添加Header和Footer的方法

    使用RecyclerView添加Header和Footer的方法

    RecyclerView雖然作為L(zhǎng)istView的替代者有著較好的性能提升,但是ListView的一些常用功能卻沒有提供,比如我們平時(shí)會(huì)經(jīng)常用到的addHeaderView,addFooterView,既然RecyclerView沒有提供這個(gè)方法,我們應(yīng)該如何為列表添加頭部和底部呢,接下來通過本文給大家介紹
    2016-03-03
  • Android中RecyclerView的item寬高問題詳解

    Android中RecyclerView的item寬高問題詳解

    RecyclerView出現(xiàn)已經(jīng)有一段時(shí)間了,相信大家肯定不陌生了,下面這篇文章主要給大家介紹了關(guān)于Android中RecyclerView的item寬高問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08

最新評(píng)論