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

Android Studio實現(xiàn)簡易登錄界面制作

 更新時間:2022年04月23日 12:00:11   作者:x97666  
這篇文章主要為大家詳細介紹了Android Studio實現(xiàn)簡易登錄界面制作,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

想要制作一個簡易的登錄界面非常容易,總體上來說就是UI布局、給定id、新建跳轉(zhuǎn)的頁面、以及輸入賬號密碼的獲取與判斷,那么接下來就開始制作吧!

1.首先就是Activity中的組件布局,這個就不一一列舉了!自己把兩個EditText和一個Button擺好就ok了,像按鈕的點擊效果可以自己設(shè)計一下(默認狀態(tài)是什么顏色,按下去是什么顏色)。

2.再一個就是要給定控件一個id

<?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:background="@drawable/img_1"
? ? android:orientation="vertical">
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:orientation="vertical">
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? android:layout_height="300dp"
? ? ? ? ? ? android:layout_marginTop="160dp"
? ? ? ? ? ? android:orientation="vertical"
? ? ? ? ? ? android:padding="30dp"
? ? ? ? ? ? android:gravity="center">
? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="60dp"
? ? ? ? ? ? ? ? android:id="@+id/EDit_username"
? ? ? ? ? ? ? ? android:hint="賬戶名"
? ? ? ? ? ? ? ? android:maxLines="1"
? ? ? ? ? ? ? ? android:textColor="#000000"/>
?
? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="60dp"
? ? ? ? ? ? ? ? android:id="@+id/EDit_password"
? ? ? ? ? ? ? ? android:layout_marginTop="15dp"
? ? ? ? ? ? ? ? android:hint="賬戶名"
? ? ? ? ? ? ? ? android:maxLines="1"
? ? ? ? ? ? ? ? android:textColor="#000000"/>
?
? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? android:layout_width="200dp"
? ? ? ? ? ? ? ? android:layout_height="60dp"
? ? ? ? ? ? ? ? android:layout_marginTop="30dp"
? ? ? ? ? ? ? ? android:id="@+id/btn_login"
? ? ? ? ? ? ? ? android:text="登錄"
? ? ? ? ? ? ? ? android:backgroundTint="@color/btn_xiaoguo"
? ? ? ? ? ? ? ? android:textSize="20sp"/>
? ? ? ? </LinearLayout>
?
</LinearLayout>
</LinearLayout>

3.然后就是要在Mainactivity.java中寫代碼了,需要申明控件id,綁定控件id及登錄按鈕的點擊事件(判斷是否是自己設(shè)定的密碼,判斷是否達到一定的長度)。  對了,還有需要定義存賬號密碼的類型名稱。

package com.example.denlu;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
?
public class MainActivity extends AppCompatActivity {
?
? ? private EditText mEDit_password; ? ? ?
? ? private EditText mEDit_username;
? ? private Button mbtn_login;
? ? private String zhanhao; ?//申明存入賬號的變量
? ? private String mima; ? //申明存入密碼的變量
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
?
? ? ? ? mEDit_username = findViewById(R.id.EDit_username); ? //綁定賬號Edit Text的id
? ? ? ? mEDit_password = findViewById(R.id.EDit_password); ?//綁定密碼Edit Text的id
? ? ? ? mbtn_login = findViewById(R.id.btn_login); ? //綁定按鈕Button的id

4.好了,現(xiàn)在要做的就是寫按鈕的點擊事件了;那么在這之前需要先新建一個跳轉(zhuǎn)之后的界面。之前也發(fā)過新建一個Activity的方法。

5.然后寫點擊事件;那么點擊事件要怎么寫,首先肯定是要把賬號與密碼都提取出來存入自定義的String變量,需要用到  .getText().toString()  這兩個函數(shù);既然提取出來了那么下一步就好辦了,直接用幾個if else if  寫幾個判斷即可。

package com.example.denlu;
?
import androidx.appcompat.app.AppCompatActivity;
?
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
?
public class MainActivity extends AppCompatActivity {
?
? ? private EditText mEDit_password;
? ? private EditText mEDit_username;
? ? private Button mbtn_login;
? ? private String zhanghao; //申明存入賬號的變量
? ? private String mima; ? //申明存入密碼的變量
?
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
?
? ? ? ? mEDit_username = findViewById(R.id.EDit_username); ? ? //綁定賬號Edit Text的id
? ? ? ? mEDit_password = findViewById(R.id.EDit_password); ? ? //綁定密碼Edit Text的id
? ? ? ? mbtn_login = findViewById(R.id.btn_login); ? ? ? ? ? ? //綁定按鈕Button的id
? ? ? ? mbtn_login.setOnClickListener(new View.OnClickListener() {
? ? ? ? ?@Override
? ? ? ? ?public void onClick(View view) {
? ? ? ? ?zhanghao = mEDit_username.getText().toString(); ? //將賬號取出來存入自定義的zhanhao變量
? ? ? ? ? ? ? ? mima = mEDit_password.getText().toString(); ? ? ? //將密碼取出來存入自定義的mima變量
? ? ? ? ? ? ? ? if (zhanghao.length()<3||zhanghao.length()>7){ ? ?//if判斷輸入賬號的長度是不是在3-7位數(shù)之間,如果不是則彈窗提示
? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this, "賬號長度應(yīng)為3-7位數(shù)之間", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? }else if (mima.length()<6||mima.length()>6){ ? ? //if判斷輸入賬號的長度是不是6位數(shù),如果不是則彈窗提示
? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"請輸入6位數(shù)的密碼",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (zhanghao.equals("abcdef")&&mima.equals("123456")){ ? ? //如果輸入的賬號密碼是“abcdef” ?“123456” 則實行頁面跳轉(zhuǎn)
? ? ? ? ? ? ? ? ? ? Intent intent = new Intent(MainActivity.this,dengluMainActivity.class);
? ? ? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"賬號或密碼輸入錯誤",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
}

嗯!就是這樣了,可能有些我沒注意講到,但是大概就是這樣了!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 浮動編輯框的具體實現(xiàn)代碼

    Android 浮動編輯框的具體實現(xiàn)代碼

    本篇文章主要介紹了Android 浮動編輯框的具體實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • Android編程實現(xiàn)仿優(yōu)酷旋轉(zhuǎn)菜單效果(附demo源碼)

    Android編程實現(xiàn)仿優(yōu)酷旋轉(zhuǎn)菜單效果(附demo源碼)

    這篇文章主要介紹了Android編程實現(xiàn)仿優(yōu)酷旋轉(zhuǎn)菜單效果的方法,較為詳細的分析了Android實現(xiàn)旋轉(zhuǎn)菜單的布局與功能實現(xiàn)技巧,并附帶完整的demo源碼供讀者下載參考,需要的朋友可以參考下
    2015-12-12
  • Android自定義View之漸變色折線圖的實現(xiàn)

    Android自定義View之漸變色折線圖的實現(xiàn)

    折線圖的實現(xiàn)方法在github上有很多開源的程序,但是對于初學(xué)者來講,簡單一點的教程可能更容易入門,下面這篇文章主要給大家介紹了關(guān)于Android自定義View之漸變色折線圖的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • Android應(yīng)用退出登錄的實現(xiàn)方法

    Android應(yīng)用退出登錄的實現(xiàn)方法

    每一個app都會有一個”退出登陸”的功能,當(dāng)點擊退出之后需要將所有的Activity都finish掉,開始是想將棧中的所有Activity清除掉,但是沒有找到方法,后來用廣播實現(xiàn)了。下面小編給大家分享android應(yīng)用退出登錄的實現(xiàn)方法,需要的朋友參考下
    2017-04-04
  • Android App中使用Glide加載圖片的教程

    Android App中使用Glide加載圖片的教程

    這篇文章主要介紹了Android App中使用Glide加載圖片的教程,包括網(wǎng)絡(luò)和本地圖片的加載方法講解,以及圖片加載異常的調(diào)試辦法,需要的朋友可以參考下
    2016-04-04
  • Android App中ViewPager與Fragment結(jié)合的一些問題解決

    Android App中ViewPager與Fragment結(jié)合的一些問題解決

    這篇文章主要介紹了Android App中ViewPager與Fragment結(jié)合的一些問題解決,重點講解了如何更新及替換ViewPager中的Fragment,需要的朋友可以參考下
    2016-03-03
  • 詳解Android獲取所有依賴庫的幾種方式

    詳解Android獲取所有依賴庫的幾種方式

    本篇文章主要介紹了詳解Android獲取所有依賴庫的幾種方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • Android NTP 時間同步機制詳解

    Android NTP 時間同步機制詳解

    這篇文章主要為大家介紹了Android NTP時間同步機制實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Android工具欄頂出轉(zhuǎn)場動畫的實現(xiàn)方法實例

    Android工具欄頂出轉(zhuǎn)場動畫的實現(xiàn)方法實例

    這篇文章主要給大家介紹了關(guān)于Android工具欄頂出轉(zhuǎn)場動畫的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • Android開發(fā)使用Messenger及Handler進行通信的方法示例

    Android開發(fā)使用Messenger及Handler進行通信的方法示例

    這篇文章主要介紹了Android開發(fā)使用Messenger及Handler進行通信的方法,結(jié)合實例形式分析了Android使用Messenger及Handler定義客戶端與服務(wù)器端實現(xiàn)通信的相關(guān)操作技巧,需要的朋友可以參考下
    2017-12-12

最新評論

四子王旗| 东山县| 玉溪市| 长泰县| 襄汾县| 定陶县| 梅河口市| 托克逊县| 延川县| 鸡东县| 柘荣县| 怀柔区| 凯里市| 珲春市| 泰来县| 蓝田县| 准格尔旗| 瓦房店市| 清流县| 高密市| 镇坪县| 天全县| 郁南县| 乳山市| 沛县| 五家渠市| 宜兴市| 峨山| 大厂| 通化市| 洛阳市| 通渭县| 惠安县| 东莞市| 渭南市| 乐亭县| 左权县| 达孜县| 池州市| 扶风县| 涪陵区|