<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一个页面"
android:layout_gravity="center"
android:textSize="40dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onclick"
android:text="进入第二个页面"
/>
</LinearLayout>
创建按钮的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);
}
}
随后会产生一个相应的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二个页面"
android:layout_gravity="center"
android:textSize="40dp"
/>
</LinearLayout>