#安卓
实现MainActivity转到其他界面的功能实现
实现步骤:
1.添加两个界面及;layout,分别为fullsreen和dialog
2.mainifest中注册两个antivity
3.向Mainactivity中代码。用intent简单的跳转
package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button b1=(Button) findViewById(R.id.button1);b1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent=new Intent(MainActivity.this,fullscreen.class);MainActivity.this.startActivity(intent);}});Button b2=(Button) findViewById(R.id.button2);b2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent=new Intent(MainActivity.this,dialogactivity.class);MainActivity.this.startActivity(intent);}});}
}
4.需要两个类dialogactivity 和 fullscreenactivity,可以自动创建,并自行补充
package com.example.myapplication;import android.os.Bundle;import androidx.appcompat.app.AppCompatActivity;public class fullscreen extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.fullscreenactivity);}}
package com.example.myapplication;import android.os.Bundle;import androidx.appcompat.app.AppCompatActivity;public class dialogactivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.dialogactivity);}}
5.运行效果