Android studio按鈕點(diǎn)擊頁面跳轉(zhuǎn)詳細(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)文章
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-03java 中sleep() 和 wait() 的對(duì)比
這篇文章主要介紹了java 中sleep() 和 wait() 的對(duì)比的相關(guān)資料,需要的朋友可以參考下2017-04-04Logback配置文件這么寫,還說你不會(huì)整理日志?
logback框架會(huì)默認(rèn)加載classpath下命名為logback-spring.xml或logback.xml的配置文件。這篇文章主要介紹了Logback配置文件寫法,需要的朋友可以參考下2020-07-07Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法
本篇文章主要介紹了Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02Maven3種打包方式中maven-assembly-plugin的使用詳解
這篇文章主要介紹了Maven3種打包方式中maven-assembly-plugin的使用,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07