Android Studio 3.1.4
Build #AI-173.4907809, built on July 24, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
1.先创建一个项目,项目文件如下:
2.activity_double_window.xml代码如下
1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".DoubleWindow"> 8 9 <Button 10 android:id="@+id/button" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:text="Button" 14 app:layout_constraintBottom_toBottomOf="parent" 15 app:layout_constraintEnd_toEndOf="parent" 16 app:layout_constraintStart_toStartOf="parent" 17 app:layout_constraintTop_toTopOf="parent" /> 18 </android.support.constraint.ConstraintLayout>
3.新建一个布局文件
4.修改好名字以后Finish
5.新建一个java类文件
6.修改好名字以后OK
7.刚创建的java类源码
1 package com.shawna.doublewindow; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 6 public class two extends Activity { 7 @Override 8 protected void onCreate(Bundle savedInstanceState){ 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.layout); 11 } 12 }
8.在AndroidManifest.xml文件中增加类文件关联
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.shawna.doublewindow"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:roundIcon="@mipmap/ic_launcher_round" 10 android:supportsRtl="true" 11 android:theme="@style/AppTheme"> 12 <activity android:name=".DoubleWindow"> 13 <intent-filter> 14 <action android:name="android.intent.action.MAIN" /> 15 16 <category android:name="android.intent.category.LAUNCHER" /> 17 </intent-filter> 18 </activity> 19 //这一句 ↓ 20 <activity android:name=".two"></activity> 21 </application> 22 23 </manifest>
9.在一开始创建的主页面上放一个按钮,按钮按下事件名称函数为play
10.DoubleWindow代码如下:
1 package com.shawna.doublewindow; 2 3 import android.content.Intent; 4 import android.support.v7.app.AppCompatActivity; 5 import android.os.Bundle; 6 import android.view.View; 7 8 public class DoubleWindow extends AppCompatActivity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_double_window); 14 } 15 16 //按钮点击事件 17 public void play(View view){ 18 //切换页面 19 Intent intent = new Intent(DoubleWindow.this,two.class); 20 startActivity(intent); 21 } 22 }
11.这样就写好了,Lucky~