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

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

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

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

UI界面設(shè)計

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

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

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

<TextView
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="登錄頁面"
? ? ? ? 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="請輸入用戶名" ? ? ? ? ? ? ??
? ? ? ?android:textColor="@android:color/black"/>

"密碼"輸入框:

<EditText
? ? ? ?android:layout_width="264dp"
? ? ? ?android:layout_height="wrap_content"
? ? ? ?android:id="@+id/ed2"
? ? ? ?android:hint="請輸入密碼"
? ? ? ?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中嵌套兩個第三層LinearLayout,且第二層LinearLayout為垂直分布,即android:orientation=“vertical”。
第三層的兩個LinearLayout中各包含一個TextView和一個EditView,第三層LinearLayout為水平分布,即android:orientation=“horizontal”。

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

<?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="登錄頁面"
? ? ? ? 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="請輸入用戶名"
? ? ? ? ? ? ? ? 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="請輸入密碼"
? ? ? ? ? ? ? ? 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代碼編寫

若用戶輸入用戶名或密碼有誤時,彈窗提示“用戶名或密碼輸入有誤,請更正后重新輸入!”。
若用戶沒有輸入用戶名或密碼,彈窗提示“用戶名與密碼不能為空!”。
當(dāng)用戶名與密碼同時輸入正確是,方可進(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,"用戶名或密碼輸入有誤,請更正后重新輸入!",Toast.LENGTH_SHORT).show();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

點(diǎn)擊登錄按鈕之后,進(jìn)入下一個界面,這時需在Manifest中添加第二個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>

第二個界面的Activity需調(diào)用第二個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);
? ? }
}

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

相關(guān)文章

  • Android編程實現(xiàn)PendingIntent控制多個鬧鐘的方法

    Android編程實現(xiàn)PendingIntent控制多個鬧鐘的方法

    這篇文章主要介紹了Android編程實現(xiàn)PendingIntent控制多個鬧鐘的方法,涉及PendingIntent屬性設(shè)置與使用的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-12-12
  • 解決Android Studio Log.v和Log.d不顯示的問題

    解決Android Studio Log.v和Log.d不顯示的問題

    這篇文章主要介紹了解決Android Studio Log.v和Log.d不顯示的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Flutter3.7新增Menu菜單組件的使用教程分享

    Flutter3.7新增Menu菜單組件的使用教程分享

    之前Flutter的菜單選擇、下拉菜單的支持非常簡單且不友好,對于非常常見的下拉菜單選擇功能是需要自己自定義實現(xiàn),今天看到Flutter3.7版本新增了一系列菜單的組件,馬上來試試
    2023-01-01
  • 詳解Android 視頻播放時停止后臺運(yùn)行的方法

    詳解Android 視頻播放時停止后臺運(yùn)行的方法

    這篇文章主要介紹了詳解Android 視頻播放時停止后臺運(yùn)行的方法的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Android Handler的postDelayed()關(guān)閉的方法及遇到問題

    Android Handler的postDelayed()關(guān)閉的方法及遇到問題

    這篇文章主要介紹了Android Handler的postDelayed()關(guān)閉的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • Android Zipalign工具優(yōu)化Android APK應(yīng)用

    Android Zipalign工具優(yōu)化Android APK應(yīng)用

    本文主要介紹Android Zipalign工具優(yōu)化Android APK應(yīng)用,這里整理了相關(guān)資料及簡單優(yōu)化實例,有需要的小伙伴可以參考下
    2016-09-09
  • Android liveData與viewBinding使用教程

    Android liveData與viewBinding使用教程

    LiveData是一種可觀察的數(shù)據(jù)存儲器類,LiveData使用觀察者模式,每當(dāng)數(shù)據(jù)發(fā)生變化時,LiveData會通知 Observer對象,我們可以在這些 Observer 對象中更新UI,ViewModel對象為特定的界面組件提供數(shù)據(jù),并包含數(shù)據(jù)處理業(yè)務(wù)邏輯,會配合LiveData一起使用
    2022-11-11
  • Android自定義View實現(xiàn)圓環(huán)進(jìn)度條

    Android自定義View實現(xiàn)圓環(huán)進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實現(xiàn)圓環(huán)進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實例

    Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實例

    這篇文章主要介紹了Android開發(fā)之完成登陸界面的數(shù)據(jù)保存回顯操作實現(xiàn)方法,結(jié)合完整實例形式較為詳細(xì)的分析了Android針對登錄數(shù)據(jù)的保存及回顯操作技巧,需要的朋友可以參考下
    2015-12-12
  • Android實現(xiàn)簡易的柱狀圖和曲線圖表實例代碼

    Android實現(xiàn)簡易的柱狀圖和曲線圖表實例代碼

    柱狀圖是統(tǒng)計圖表中經(jīng)常用到的一種圖表,比如降雨量之類的統(tǒng)計展示。這篇文章主要給大家介紹了關(guān)于利用Android如何實現(xiàn)簡易的柱狀圖和曲線圖表的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。
    2017-12-12

最新評論

定远县| 宝兴县| 凤翔县| 新巴尔虎左旗| 马公市| 甘南县| 牡丹江市| 亳州市| 江阴市| 承德市| 定结县| 淮滨县| 浑源县| 陇南市| 开远市| 上饶市| 鹤岗市| 峨眉山市| 乐陵市| 宜昌市| 时尚| 资兴市| 利津县| 海安县| 丹棱县| 黄骅市| 利川市| 舟曲县| 灵璧县| 溆浦县| 旬阳县| 潞城市| 浦城县| 荣昌县| 铜山县| 南召县| 南皮县| 台州市| 华容县| 鄯善县| 石景山区|