最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)簡(jiǎn)易登陸注冊(cè)邏輯的實(shí)例代碼

 更新時(shí)間:2021年06月20日 15:07:00   作者:青絲纏光陰  
在android的應(yīng)用中越來越多的包含了網(wǎng)絡(luò)互動(dòng)功能,這就帶來了注冊(cè),登陸賬號(hào)功能,這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)簡(jiǎn)易登陸注冊(cè)邏輯的相關(guān)資料,需要的朋友可以參考下

大家好,今天給大家?guī)鞟ndroid制作登錄和注冊(cè)功能的實(shí)現(xiàn),當(dāng)我們面臨制作登錄和注冊(cè)功能的實(shí)現(xiàn)時(shí),我們需要先設(shè)計(jì)登錄界面的布局和注冊(cè)界面的布局,做到有完整的思路時(shí)才開始實(shí)現(xiàn)其功能效果會(huì)更好。

activity_login

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_username"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginStart="40dp"
        android:layout_marginTop="100dp"
        android:gravity="center_vertical"
        android:text="賬號(hào):"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_password"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginStart="40dp"
        android:gravity="center_vertical"
        android:text="密碼:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_username" />

    <EditText
        android:id="@+id/ed_username"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_marginTop="100dp"
        app:layout_constraintLeft_toRightOf="@id/tv_username"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/ed_password"
        android:layout_width="300dp"
        android:inputType="textPassword"
        android:layout_height="40dp"
        app:layout_constraintLeft_toRightOf="@id/tv_password"
        app:layout_constraintTop_toBottomOf="@id/ed_username" />

    <Button
        android:id="@+id/bu_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="300dp"
        android:text="登錄"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/bu_register"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/bu_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="300dp"
        android:text="注冊(cè)"
        app:layout_constraintLeft_toRightOf="@id/bu_login"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

LoginActivity

package com.jld.exam;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {
    EditText ed_username;
    EditText ed_password;
    Button bu_login;
    Button bu_register;
    String username;
    String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        ed_username = findViewById(R.id.ed_username);
        ed_password = findViewById(R.id.ed_password);
        bu_login = findViewById(R.id.bu_login);
        bu_register = findViewById(R.id.bu_register);

        //登錄按鈕監(jiān)聽
        bu_login.setOnClickListener(v -> {
            username = ed_username.getText().toString();
            password = ed_password.getText().toString();

            //登陸的簡(jiǎn)單邏輯
            if (username.equals("")) {
                Toast.makeText(LoginActivity.this, "請(qǐng)輸入用戶名", Toast.LENGTH_SHORT).show();
            } else if (password.equals("")) {
                Toast.makeText(LoginActivity.this, "請(qǐng)輸入密碼", Toast.LENGTH_SHORT).show();
            } else if (!username.equals("root") || !password.equals("123456")) {
                Toast.makeText(LoginActivity.this, "用戶名或密碼錯(cuò)誤", Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });

        //注冊(cè)按鈕監(jiān)聽
        bu_register.setOnClickListener(v -> {
            Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
            startActivity(intent);
        });
    }

}

activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="商品列表"
        android:layout_marginBottom="30dp"
        android:gravity="center_horizontal"/>
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

MainActivity

package com.jld.exam;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class MainActivity extends AppCompatActivity {

    RecyclerViewAdapter recyclerViewAdapter;
    private final int[] icno = {R.drawable.clock, R.drawable.signal, R.drawable.box,
            R.drawable.second, R.drawable.elephone, R.drawable.ff, R.drawable.notebook, R.drawable.mark, R.drawable.yx,
            R.drawable.shop, R.drawable.theme, R.drawable.xl,};
    private final String[] name = {"時(shí)鐘", "信號(hào)", "寶箱", "秒鐘", "大象", "FF", "記事本", "書簽", "印象", "商店", "主題", "迅雷"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);//GridLayoutManager
        GridLayoutManager gridLayoutManager = new GridLayoutManager(MainActivity.this, 3);//創(chuàng)建recyclerview
        RecyclerView recyclerView = findViewById(R.id.recycler);//設(shè)定布局管理器
        recyclerView.setLayoutManager(gridLayoutManager);//創(chuàng)建適配器
        recyclerViewAdapter = new RecyclerViewAdapter(icno, name);
        recyclerView.setAdapter(recyclerViewAdapter);//設(shè)定適配器
    }
}

activity_register

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RegisterActivity">

    <TextView
        android:id="@+id/textView0"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:gravity="center"
        android:text="用戶注冊(cè)"
        android:textSize="30sp"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:drawableStart="@drawable/account"
        android:gravity="center_vertical"
        android:text="用戶名:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView0" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_weight="10"
        android:autofillHints=""
        android:gravity="center_horizontal"
        android:inputType="text"

        app:layout_constraintLeft_toRightOf="@id/textView1"
        app:layout_constraintTop_toBottomOf="@id/textView0" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_weight="2"
        android:drawableStart="@drawable/password"
        android:gravity="center_vertical"
        android:text="新密碼:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView1" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_weight="10"
        android:autofillHints=""
        android:gravity="center_horizontal"
        android:inputType="textPassword"
        app:layout_constraintLeft_toRightOf="@id/textView2"
        app:layout_constraintTop_toBottomOf="@id/editText1" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:drawableStart="@drawable/phone"
        android:gravity="center_vertical"
        android:text="手機(jī)電話:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView2" />

    <EditText
        android:id="@+id/editText5"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_weight="10"
        android:autofillHints=""
        android:gravity="center_horizontal"
        android:inputType="phone"
        app:layout_constraintLeft_toRightOf="@id/textView5"
        app:layout_constraintTop_toBottomOf="@id/editText2" />


    <TextView
        android:id="@+id/textView7"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:drawableStart="@drawable/email"
        android:gravity="center_vertical"
        android:text="E_mail:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/editText5" />

    <EditText
        android:id="@+id/editText7"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_weight="10"
        android:autofillHints=""
        android:gravity="center_horizontal"
        android:inputType="textEmailAddress"
        app:layout_constraintLeft_toRightOf="@id/textView7"
        app:layout_constraintTop_toBottomOf="@id/editText5" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:drawableStart="@drawable/gender"
        android:gravity="center_vertical"
        android:text="性別:"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView7" />

    <RadioGroup
        android:id="@+id/radioGroup8"
        android:layout_width="300dp"
        android:layout_height="40dp"
        android:layout_weight="10"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        app:layout_constraintLeft_toRightOf="@id/textView8"
        app:layout_constraintTop_toBottomOf="@id/editText7">

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男" />
    </RadioGroup>


    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="保存"
        app:layout_constraintEnd_toStartOf="@id/button2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/radioGroup8" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="取消"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/button1"
        app:layout_constraintTop_toBottomOf="@id/radioGroup8" />
</androidx.constraintlayout.widget.ConstraintLayout>


RegisterActivity

package com.jld.exam;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class RegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
    }
}

recyc_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="center_horizontal"
        android:contentDescription="TODO"
        android:scaleType="centerInside"
        android:src="@drawable/ic_launcher_background" />

    <TextView
        android:id="@+id/tv_desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint="銷售價(jià)格"
        android:textSize="14sp" />

</LinearLayout>



RecyclerViewAdapter

package com.jld.exam;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    private final int[] icno;
    private final String[] desc;

    public RecyclerViewAdapter(int[] icno, String[] desc) {
        this.icno = icno;
        this.desc = desc;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyc_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.imageView.setImageResource(icno[position]);
        holder.textView.setText(desc[position]);
    }

    @Override
    public int getItemCount() {
        return icno.length;
    }

    //ViewHolder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        View item;
        ImageView imageView;
        TextView textView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item = itemView;
            imageView = itemView.findViewById(R.id.iv_image);
            textView = itemView.findViewById(R.id.tv_desc);
        }
    }
}

總結(jié)

到此這篇關(guān)于Android實(shí)現(xiàn)簡(jiǎn)易登陸注冊(cè)邏輯的文章就介紹到這了,更多相關(guān)Android登陸注冊(cè)邏輯內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • RecyclerView 源碼淺析測(cè)量 布局 繪制 預(yù)布局

    RecyclerView 源碼淺析測(cè)量 布局 繪制 預(yù)布局

    這篇文章主要介紹了RecyclerView 源碼淺析測(cè)量 布局 繪制 預(yù)布局,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android平臺(tái)下輕量級(jí)http網(wǎng)絡(luò)傳輸庫

    Android平臺(tái)下輕量級(jí)http網(wǎng)絡(luò)傳輸庫

    這篇文章主要介紹了Android平臺(tái)下輕量級(jí)http網(wǎng)絡(luò)傳輸庫的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • Android Studio注釋模板介紹

    Android Studio注釋模板介紹

    這篇文章主要介紹了Android Studio注釋模板介紹,之前Eclipse敲/**加回車,模板就出來了,而Android Studio卻不可以自定義,現(xiàn)在我給大家介紹下用live templates替代,需要的朋友可以參考下
    2015-07-07
  • Android查看文件夾大小以及刪除文件夾的工具類

    Android查看文件夾大小以及刪除文件夾的工具類

    這篇文章主要介紹了Android查看文件夾大小以及刪除文件夾的工具類,Android計(jì)算文件夾大小和刪除目錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • TextView顯示系統(tǒng)時(shí)間(時(shí)鐘功能帶秒針變化

    TextView顯示系統(tǒng)時(shí)間(時(shí)鐘功能帶秒針變化

    用System.currentTimeMillis()可以獲取系統(tǒng)當(dāng)前的時(shí)間,我們可以開啟一個(gè)線程,然后通過handler發(fā)消息,來實(shí)時(shí)的更新TextView上顯示的系統(tǒng)時(shí)間,可以做一個(gè)時(shí)鐘的功能
    2013-11-11
  • Android解決ScrollView下嵌套ListView和GridView中內(nèi)容顯示不全的問題

    Android解決ScrollView下嵌套ListView和GridView中內(nèi)容顯示不全的問題

    今天小編就為大家分享一篇關(guān)于Android解決ScrollView下嵌套ListView和GridView中內(nèi)容顯示不全的問題,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • OpenHarmony實(shí)現(xiàn)類Android短信驗(yàn)證碼及倒計(jì)時(shí)流程詳解

    OpenHarmony實(shí)現(xiàn)類Android短信驗(yàn)證碼及倒計(jì)時(shí)流程詳解

    這篇文章主要介紹了OpenHarmony實(shí)現(xiàn)類Android短信驗(yàn)證碼及倒計(jì)時(shí)流程,發(fā)送短信驗(yàn)證碼后,一般在界面上都會(huì)有一個(gè)倒計(jì)時(shí)的顯示.在安卓中,實(shí)現(xiàn)類似的倒計(jì)時(shí)有多種方式,當(dāng)然背后的基本原理都是設(shè)定一個(gè)初始值,然后每過一定的間隔時(shí)間執(zhí)行操作
    2022-11-11
  • Android ViewPager實(shí)現(xiàn)智能無限循環(huán)滾動(dòng)回繞效果

    Android ViewPager實(shí)現(xiàn)智能無限循環(huán)滾動(dòng)回繞效果

    這篇文章主要為大家詳細(xì)介紹了Android ViewPager實(shí)現(xiàn)智能無限循環(huán)滾動(dòng)回繞效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android面試筆記之常問的Context

    Android面試筆記之常問的Context

    Android技術(shù)面試確實(shí)常常被問到Context,大概問題就是說說你對(duì)Context的理解吧,當(dāng)時(shí)腦袋里浮現(xiàn)了是原來看到的文章片段亂說一通,這樣還是不行的。平時(shí)還是多積累知識(shí),深刻理解Context,在項(xiàng)目開發(fā)過程中也能避免一些陷入坑中。下面就來看看個(gè)人的一些總結(jié)吧。
    2016-12-12
  • Android實(shí)現(xiàn)擴(kuò)展Menu的方法

    Android實(shí)現(xiàn)擴(kuò)展Menu的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)擴(kuò)展Menu的方法,涉及Android操作menu菜單的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10

最新評(píng)論

延寿县| 益阳市| 西和县| 定远县| 青浦区| 那坡县| 靖西县| 刚察县| 内黄县| 宁德市| 喀什市| 获嘉县| 阳东县| 正镶白旗| 玉溪市| 乐陵市| 且末县| 芦溪县| 元谋县| 丰镇市| 汕尾市| 黎平县| 满城县| 浑源县| 通辽市| 长春市| 托克托县| 峨边| 香河县| 吉林市| 黔西县| 南郑县| 三都| 三亚市| 九龙县| 沐川县| 三穗县| 兰西县| 额济纳旗| 陆河县| 宜兰县|