AndroidStudio多窗口項目


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~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM