Android 实现页面之间跳转(显示意图)——小白一看就会

Android 实现页面之间跳转(显示意图)——小白一看就会

Android 页面之间跳转——显示意图跳转

利用Intent进行跳转

Intent方法进行页面跳转适用于两个Activity之间的跳转,按返回键可以直接返回到前一个页面。

使用时需要注意在Manifest.xml文件中注册Activity

activity_main.xml(Mainactivity布局)

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:id="@+id/tv_first"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="第一个页面"

android:layout_gravity="center"

android:textSize="40dp"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="onclick"

android:text="进入第二个页面"

/>

创建按钮的onclick方法

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public void onclick(View view) {

Intent intent = new Intent(this,SecondActivity.class);

startActivity(intent);

}

}

Intent方法两个参数,第一个是上下文,第二个是跳转的Activity

新建Activity方法:

.new——activity——empty activity

随后会产生一个相应的布局文件

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="第二个页面"

android:layout_gravity="center"

android:textSize="40dp"

/>

如图是运行效果。点击按钮 跳转到第二个页面

Andriod项目默认生成一个MainActivity.java,如果执行,会默认执行它,但如果在别的Activity中写了登录界面,如何先执行登录呢?

假设是这种情况,打开/项目名/AndroidManifest.xml这个xml文件中

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

就理解为过滤器,它指定了启动应用程序的Intent对象的动作和类型

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

这样第一个启动的就是SecondActivity了

首个启动的设置为

其他的设置为

相关推荐

Java开发笔记(一百一十九)AWT布局
S365网络超时

Java开发笔记(一百一十九)AWT布局

08-02 👁️ 1310
Flash 8文件格式官方规范:SWF & FLV详解
28365备用网址官方网站

Flash 8文件格式官方规范:SWF & FLV详解

08-15 👁️ 9468
0比0进点球怎么猜比分,足球比赛0比0算小球吗
28365备用网址官方网站

0比0进点球怎么猜比分,足球比赛0比0算小球吗

07-15 👁️ 3064
1998年国际足联世界杯
36365

1998年国际足联世界杯

06-27 👁️ 5718