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

Android studio按鈕點(diǎn)擊頁面跳轉(zhuǎn)詳細(xì)步驟

 更新時(shí)間:2023年06月13日 15:04:45   作者:Swallow_L02  
在Android應(yīng)用程序中,頁面跳轉(zhuǎn)是非常常見的操作,下面這篇文章主要給大家介紹了關(guān)于Android studio按鈕點(diǎn)擊頁面跳轉(zhuǎn)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

(1)先創(chuàng)建一個(gè)要跳轉(zhuǎn)的頁面,即一個(gè)新的頁面,該頁面是點(diǎn)擊之后跳轉(zhuǎn)的。

步驟:app--->src-->main-->res-->layout(右擊)-->New-->Activity-->Empty Activity

 創(chuàng)建好以后,此時(shí)會(huì)生成一個(gè)同名的java文件。

初始時(shí)的界面代碼如下,界面展示在后面,僅供參考。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="用戶名:"/>
        <EditText
            android:id="@+id/edit1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="____________"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密碼:"/>
        <EditText
            android:id="@+id/edit2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="____________"
            android:password="true"/>
    </LinearLayout>
    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登錄"/>
</LinearLayout>

跳轉(zhuǎn)的界面代碼,同樣界面展示在后面。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/bg">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:textColor="#DDE0E4"
        android:text="歡迎進(jìn)入智慧農(nóng)業(yè)系統(tǒng)"
        />
</LinearLayout>

由于頁面跳轉(zhuǎn)沒有變換,變化的是主界面,在主界面點(diǎn)擊按鈕,使頁面發(fā)生變化,因此只需要編寫

MainActivity.java文件。

注:不同的文件名,包名不同,以下為我個(gè)人的編寫代碼,僅供參考。

package com.example.signin;
 
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 Button btn;
    private EditText edit1;
    private EditText edit2;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        initView();
    }
 
    private void initView() {
        btn = (Button) findViewById(R.id.btn);
        edit1 = (EditText) findViewById(R.id.edit1);
        edit2 = (EditText) findViewById(R.id.edit2);
 
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(edit1.getText().toString().equals("aaa") &&
                   edit2.getText().toString().equals("aaa")){
                    Intent intent = new Intent(MainActivity.this,nextActive.class);
                    startActivity(intent);
                }
                else {
                    Toast.makeText(MainActivity.this,"輸入有誤,請(qǐng)重新輸 
                     入",Toast.LENGTH_LONG).show();
                }
            }
        });
    }
 
}

以下是我完成的登錄跳轉(zhuǎn)頁面,僅供參考。

初始時(shí)的界面:

輸入正確的用戶名和密碼以后,跳轉(zhuǎn)到如下界面,僅供參考。

 如果沒有輸入正確,將有文字提示:

總結(jié)

到此這篇關(guān)于Android studio按鈕點(diǎn)擊頁面跳轉(zhuǎn)的文章就介紹到這了,更多相關(guān)Android studio點(diǎn)擊頁面跳轉(zhuǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring MVC溫故而知新系列教程之從零開始

    Spring MVC溫故而知新系列教程之從零開始

    Spring MVC 框架在 Java 的 Web 項(xiàng)目中應(yīng)該是無人不知的吧,你不會(huì)搭建一個(gè) Spring 框架?作為身為一個(gè)剛剛學(xué)習(xí)Java的我都會(huì),如果你不會(huì)的話,那可真令人憂傷。下面這篇文章主要給大家介紹了關(guān)于Spring MVC從零開始的相關(guān)資料,需要的朋友可以參考下
    2018-05-05
  • Java對(duì)比兩個(gè)實(shí)體的差異分析

    Java對(duì)比兩個(gè)實(shí)體的差異分析

    這篇文章主要介紹了Java對(duì)比兩個(gè)實(shí)體的差異分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • java使用泛型實(shí)現(xiàn)棧結(jié)構(gòu)示例分享

    java使用泛型實(shí)現(xiàn)棧結(jié)構(gòu)示例分享

    泛型是Java SE5.0的重要特性,使用泛型編程可以使代碼獲得最大的重用。由于在使用泛型時(shí)要指明泛型的具體類型,這樣就避免了類型轉(zhuǎn)換。本實(shí)例將使用泛型來實(shí)現(xiàn)一個(gè)棧結(jié)構(gòu),并對(duì)其進(jìn)行測(cè)試
    2014-03-03
  • java 中sleep() 和 wait() 的對(duì)比

    java 中sleep() 和 wait() 的對(duì)比

    這篇文章主要介紹了java 中sleep() 和 wait() 的對(duì)比的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • Logback配置文件這么寫,還說你不會(huì)整理日志?

    Logback配置文件這么寫,還說你不會(huì)整理日志?

    logback框架會(huì)默認(rèn)加載classpath下命名為logback-spring.xml或logback.xml的配置文件。這篇文章主要介紹了Logback配置文件寫法,需要的朋友可以參考下
    2020-07-07
  • java中的switch case語句使用詳解

    java中的switch case語句使用詳解

    這篇文章主要介紹了java中的switch case語句使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法

    Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法

    本篇文章主要介紹了Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • JAVA_基本LDAP操作實(shí)例

    JAVA_基本LDAP操作實(shí)例

    這篇文章介紹了JAVA_基本LDAP操作實(shí)例,有需要的朋友可以參考一下
    2013-09-09
  • Maven3種打包方式中maven-assembly-plugin的使用詳解

    Maven3種打包方式中maven-assembly-plugin的使用詳解

    這篇文章主要介紹了Maven3種打包方式中maven-assembly-plugin的使用,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Flink入門級(jí)應(yīng)用域名處理示例

    Flink入門級(jí)應(yīng)用域名處理示例

    這篇文章主要介紹了一個(gè)比較簡(jiǎn)單的入門級(jí)Flink應(yīng)用,代碼很容易寫,主要用到的算子有FlatMap、KeyBy、Reduce,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-03-03

最新評(píng)論