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

Android?studio實(shí)現(xiàn)app登錄界面

 更新時(shí)間:2022年04月23日 15:29:00   作者:Run  
這篇文章主要為大家詳細(xì)介紹了Android?studio實(shí)現(xiàn)app登錄界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android studio設(shè)計(jì)app登錄界面,供大家參考,具體內(nèi)容如下

UI界面設(shè)計(jì)

在設(shè)計(jì)登錄界面時(shí),可以使用不同布局方式來實(shí)現(xiàn)該功能,通常情況下使用的是LinearLayout(線性布局)和TableLayout(表格布局),在本文中使用線性布局。登陸界面需要幾項(xiàng)必不可少的控件,如下所示:

1、TextView:用于顯示標(biāo)題和“用戶名"和"密碼"的提示;

標(biāo)題設(shè)置

<TextView
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="登錄頁(yè)面"
? ? ? ? android:textSize="30dp"
? ? ? ? android:textColor="@android:color/black"
? ? ? ? android:layout_gravity="center_horizontal"/>

"用戶名"提示

<TextView
? ? ? ?android:layout_width="65dp"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:text="用戶名:"
? ? ? ?android:textSize="16dp"
? ? ? ?android:textColor="@android:color/black"/>

"密碼"提示:

<TextView
? ? ? ?android:layout_width="65dp"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:text="密碼:"
? ? ? ?android:textSize="16dp"
? ? ? ?android:textColor="@android:color/black"/>

2、EditView:用于輸入"用戶名"和"密碼";

"用戶名"輸入框:

<EditText
? ? ? ?android:layout_width="264dp"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:id="@+id/ed1"
? ? ? ?android:hint="請(qǐng)輸入用戶名" ? ? ? ? ? ? ??
? ? ? ?android:textColor="@android:color/black"/>

"密碼"輸入框:

<EditText
? ? ? ?android:layout_width="264dp"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:id="@+id/ed2"
? ? ? ?android:hint="請(qǐng)輸入密碼"
? ? ? ?android:textColor="@android:color/black"/>

3、Button:用于控制登錄。

Button登錄按鈕:

<Button
? ? ? ? android:layout_width="285dp"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="登錄"
? ? ? ? android:textSize="20dp"
? ? ? ? android:id="@+id/bt"
? ? ? ? android:layout_gravity="center_horizontal" />/>

本文使用三層LinearLayout互相嵌套,第一層LinearLayout中包括標(biāo)題(TextView)和第二層LinearLayout以及登錄按鈕(Button)。第一層LinearLayout使用垂直分布,即android:orientation=“vertical”。
第二層LinearLayout中嵌套兩個(gè)第三層LinearLayout,且第二層LinearLayout為垂直分布,即android:orientation=“vertical”。
第三層的兩個(gè)LinearLayout中各包含一個(gè)TextView和一個(gè)EditView,第三層LinearLayout為水平分布,即android:orientation=“horizontal”。

總的UI設(shè)計(jì)如下所示。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:id="@+id/activity_main"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:paddingBottom="@dimen/activity_vertical_margin"
? ? android:paddingLeft="@dimen/activity_horizontal_margin"
? ? android:paddingRight="@dimen/activity_horizontal_margin"
? ? android:paddingTop="@dimen/activity_vertical_margin"
? ? tools:context="com.example.activities.MainActivity"
? ? android:orientation="vertical"
? ? android:weightSum="1">

? ? <TextView
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="登錄頁(yè)面"
? ? ? ? android:textSize="30dp"
? ? ? ? android:textColor="@android:color/black"
? ? ? ? android:layout_gravity="center_horizontal"/>
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:orientation="vertical"
? ? ? ? android:gravity="center"
? ? ? ? android:layout_weight="0.55">
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="300dp"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:orientation="horizontal">
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:layout_width="65dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="用戶名:"
? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? android:textColor="@android:color/black"/>

? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? android:layout_width="264dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:id="@+id/ed1"
? ? ? ? ? ? ? ? android:hint="請(qǐng)輸入用戶名"
? ? ? ? ? ? ? ? android:textColor="@android:color/black"/>
? ? ? ? </LinearLayout>
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="300dp"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:orientation="horizontal">
? ? ? ? ? ? <TextView
? ? ? ? ? ? ? ? android:layout_width="65dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="密碼:"
? ? ? ? ? ? ? ? android:textSize="16dp"
? ? ? ? ? ? ? ? android:textColor="@android:color/black"/>
? ? ? ? ? ? <EditText
? ? ? ? ? ? ? ? android:layout_width="264dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:id="@+id/ed2"
? ? ? ? ? ? ? ? android:hint="請(qǐng)輸入密碼"
? ? ? ? ? ? ? ? android:textColor="@android:color/black"/>
? ? ? ? </LinearLayout>
? ? </LinearLayout>


? ? <Button
? ? ? ? android:layout_width="285dp"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="登錄"
? ? ? ? android:textSize="20dp"
? ? ? ? android:id="@+id/bt"
? ? ? ? android:layout_gravity="center_horizontal" />/>
</LinearLayout>

效果如圖所示。

Java代碼編寫

若用戶輸入用戶名或密碼有誤時(shí),彈窗提示“用戶名或密碼輸入有誤,請(qǐng)更正后重新輸入!”。
若用戶沒有輸入用戶名或密碼,彈窗提示“用戶名與密碼不能為空!”。
當(dāng)用戶名與密碼同時(shí)輸入正確是,方可進(jìn)入系統(tǒng)。

package com.example.activities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
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 usertext;
? ? private EditText passtext;
? ? private Button loginbutton;

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? usertext=(EditText)this.findViewById(R.id.ed1);
? ? ? ? passtext=(EditText)this.findViewById(R.id.ed2);
? ? ? ? loginbutton=(Button)this.findViewById(R.id.bt);
? ? ? ? loginbutton.setOnClickListener(new ButtonListener());
? ? }
? ? private class ButtonListener implements View.OnClickListener{
? ? ? ? @Override
? ? ? ? public void onClick(View v){
? ? ? ? ? ? String user=usertext.getText().toString();
? ? ? ? ? ? String pass=passtext.getText().toString();
? ? ? ? ? ? if (user.equals("")||pass.equals("")){
? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"用戶名與密碼不能為空!",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? }
? ? ? ? ? ? else if (user.equals("denglu")&&pass.equals("0000")){
? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"登陸成功",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this,TwoActivity.class);
? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"用戶名或密碼輸入有誤,請(qǐng)更正后重新輸入!",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

點(diǎn)擊登錄按鈕之后,進(jìn)入下一個(gè)界面,這時(shí)需在Manifest中添加第二個(gè)Activity的名稱

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
? ? package="com.example.activities">

? ? <application
? ? ? ? <activity android:name=".MainActivity">
? ? ? ? ? ? <intent-filter>
? ? ? ? ? ? ? ? <action android:name="android.intent.action.MAIN" />

? ? ? ? ? ? ? ? <category android:name="android.intent.category.LAUNCHER" />
? ? ? ? ? ? </intent-filter>
? ? ? ? </activity>
? ? ? ? <activity android:name=".TwoActivity"></activity>
? ? </application>

</manifest>

第二個(gè)界面的Activity需調(diào)用第二個(gè)xlm的layout,如下所示

package com.example.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class TwoActivity extends AppCompatActivity {

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

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

相關(guān)文章

  • Android實(shí)現(xiàn)彈窗進(jìn)度條效果

    Android實(shí)現(xiàn)彈窗進(jìn)度條效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)彈窗進(jìn)度條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android開發(fā)實(shí)現(xiàn)NFC刷卡讀取的兩種方式

    Android開發(fā)實(shí)現(xiàn)NFC刷卡讀取的兩種方式

    這篇文章主要為大家詳細(xì)介紹了Android開發(fā)中實(shí)現(xiàn)NFC刷卡讀取的兩種方式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Flutter StatefulBuilder實(shí)現(xiàn)局部刷新實(shí)例詳解

    Flutter StatefulBuilder實(shí)現(xiàn)局部刷新實(shí)例詳解

    這篇文章主要為大家介紹了Flutter StatefulBuilder實(shí)現(xiàn)局部刷新實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android開發(fā) -- setTag的妙用和The key must be an application-specific resource id 異常

    Android開發(fā) -- setTag的妙用和The key must be an application-specif

    本文主要介紹Android開發(fā)setTag的妙用,小編覺得挺實(shí)用的,給大家一個(gè)參考,希望對(duì)大家學(xué)習(xí)有所幫助。
    2016-06-06
  • 分享Android仿刮獎(jiǎng)效果控件

    分享Android仿刮獎(jiǎng)效果控件

    這篇文章主要為大家分享了Android仿刮獎(jiǎng)效果控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android利用zxing生成二維碼的過程記錄

    Android利用zxing生成二維碼的過程記錄

    Android中二維碼生成的最常用庫(kù)就是zxing了,正好目前項(xiàng)目有了生成二維碼的需求,所以下面這篇文章主要給大家介紹了關(guān)于Android利用zxing生成二維碼的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • Android Material Design 陰影實(shí)現(xiàn)示例

    Android Material Design 陰影實(shí)現(xiàn)示例

    這篇文章主要介紹了Android Material Design 陰影實(shí)現(xiàn)示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-04-04
  • Android中巧妙的實(shí)現(xiàn)緩存詳解

    Android中巧妙的實(shí)現(xiàn)緩存詳解

    采用緩存,可以進(jìn)一步大大緩解數(shù)據(jù)交互的壓力,有的時(shí)候?yàn)榱丝焖俨樵儠?huì)被多次調(diào)用的數(shù)據(jù),或者構(gòu)建比較廢時(shí)的實(shí)例,我們一般使用緩存的方法。無論大型或小型應(yīng)用,靈活的緩存可以說不僅大大減輕了服務(wù)器的壓力,而且因?yàn)楦焖俚挠脩趔w驗(yàn)而方便了用戶。下面來一起看看吧。
    2016-11-11
  • Android自定義控件實(shí)現(xiàn)方向盤效果

    Android自定義控件實(shí)現(xiàn)方向盤效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)方向盤效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • Android實(shí)現(xiàn)加載狀態(tài)視圖切換效果

    Android實(shí)現(xiàn)加載狀態(tài)視圖切換效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)加載狀態(tài)視圖切換效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07

最新評(píng)論