当前位置:首页 » 《随便一记》 » 正文

Android studio 按钮点击页面跳转

18 人参与  2023年03月31日 09:29  分类 : 《随便一记》  评论

点击全文阅读


(1)先创建一个要跳转的页面,即一个新的页面,该页面是点击之后跳转的。

步骤:app--->src-->main-->res-->layout(右击)-->New-->Activity-->Empty Activity

 创建好以后,此时会生成一个同名的java文件。

初始时的界面代码如下,界面展示在后面,仅供参考。

<?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>

跳转的界面代码,同样界面展示在后面。

<?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="欢迎进入智慧农业系统"        /></LinearLayout>

由于页面跳转没有变换,变化的是主界面,在主界面点击按钮,使页面发生变化,因此只需要编写

MainActivity.java文件。

注:不同的文件名,包名不同,以下为我个人的编写代码,仅供参考。

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,"输入有误,请重新输                      入",Toast.LENGTH_LONG).show();                }            }        });    }}

以下是我完成的登录跳转页面,仅供参考。

初始时的界面:

输入正确的用户名和密码以后,跳转到如下界面,仅供参考。

 如果没有输入正确,将有文字提示:


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/57500.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (此去经年无故人)南初陆南城:结局+番外精品选集起点章节+阅读即将发布预订
  • 沈凝夏叶晚怡附加完整在线阅读(归雁不栖故人枝)最近更新列表
  • 剧情人物是时初,白浩雄的玄幻言情小说《召诸神,踏万界,天命帝女逆乾坤》,由网络作家&ldquo;海鸥&rdquo;所著,情节扣人心弦,本站TXT全本,欢迎阅读!本书共计381345字,185章节,:结局+番外免费品鉴:结局+番外评价五颗星
  • 凤青禾,江明远,***枢小说(别人修仙我捡漏,卷王们破防了)最近更新(凤青禾,江明远,***枢)整本无套路阅读
  • 薛梨小说无删减+后续(曾经亲情似草芥)畅享阅读
  • 沈南栀小说(穿越时空,我要修补时空裂缝)章节目录+起点章节(沈南栀)全篇清爽版在线
  • 未婚妻被巨蟒缠身,我该吃就吃该喝就喝前言+后续_阿豪林月周然后续+番外_小说后续在线阅读_无删减免费完结_
  • 陆骁,陆本初小说(陆骁,陆本初)(癫!睁眼穿成老太太挥鞭***逆子)前传+阅读全新作品预订
  • 姐姐含冤而死后冥王另娶,我杀穿整个地府在线阅读_阎罗殿殷红别提一口气完结_小说后续在线阅读_无删减免费完结_
  • (书荒必看)毒后重生:疯王的神医小娇妻沈清歌,萧绝:+后续热血十足
  • 重生后我和太监联手灭了敌国喻辰,林雪续集(重生后我和太监联手灭了敌国)终极反转(喻辰,林雪)全篇一口气阅读
  • 我不做灵媒后,自称灵媒摆渡人的养妹害怕了内容精选_苏晓霍老阿姐无广告_小说后续在线阅读_无删减免费完结_

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1