【Android Studio】Android实现跳转功能

最近在玩Esp32,需要APP,顺带学了下这方面的东西。

 

主要实现功能: 从主  mainActivity  跳转到otherActivity。

新建一个hello工程,添加 otherActivity 和 otherxml.xml;

mainActivity内容:

package com.example.xiaoyehack.test;

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

import android.view.View;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {

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

    public void skip(View view){
        Intent intent = new Intent();
        intent.setClass(MainActivity.this,otherActivity.class);
        startActivity(intent);
    }
}

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="79dp"
        android:layout_marginStart="148dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="148dp"
        android:layout_marginBottom="276dp"
        android:onClick="skip"
        android:text="点击跳转"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="122dp"
        android:layout_marginTop="105dp"
        android:layout_marginEnd="122dp"
        android:layout_marginBottom="92dp"
        android:text="点击下面按钮实现跳转"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

  

otherActivity内容:
package com.example.xiaoyehack.test;

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

public class otherActivity extends AppCompatActivity {

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

}

  otherxml内容:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="67dp"
        android:layout_marginStart="116dp"
        android:layout_marginTop="146dp"
        android:layout_marginEnd="100dp"
        android:layout_marginBottom="346dp"
        android:text="不要吹牛皮,就是一把梭!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>

 

 

赏币地址:

https://download.csdn.net/download/qq_18187161/10882442

 

 

无币地址:

链接:https://pan.baidu.com/s/1NWPNbkQxMgkGxpNPX9loLw
提取码:qhnx
提取码复制可见。

 

转载于:https://www.cnblogs.com/xiaoyehack/p/10188830.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要创建两个Activity,一个用于登录,一个用于注册。我们称之为LoginActivity和RegisterActivity。 在LoginActivity中,你需要添加一个“登录”按钮,当用户点击该按钮时,你需要验证用户输入的用户名和密码是否正确。如果验证通过,则跳转到主Activity,否则,显示错误消息。 在RegisterActivity中,你需要添加一个“注册”按钮,当用户点击该按钮时,你需要将用户输入的用户名和密码保存到本地数据库中。 接下来,你需要在LoginActivity和RegisterActivity中添加一些代码,以实现跳转功能。具体步骤如下: 1. 在LoginActivity中,添加以下代码: ``` // 跳转到注册页面 TextView registerTextView = findViewById(R.id.registerTextView); registerTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); startActivity(intent); } }); ``` 2. 在RegisterActivity中,添加以下代码: ``` // 跳转到登录页面 TextView loginTextView = findViewById(R.id.loginTextView); loginTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(RegisterActivity.this, LoginActivity.class); startActivity(intent); } }); ``` 现在,当用户点击“注册”按钮时,会跳转到RegisterActivity;当用户点击“登录”按钮时,会跳转到LoginActivity。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值