80,471
社区成员




@Override
public void onClick(View v) {
androidx.fragment.app.FragmentManager fragmentManager = getSupportFragmentManager();
androidx.fragment.app.FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
switch (v.getId()) {
case R.id.frg1:
Log.d(TAG, "点击跳转事件");
beginTransaction.replace(R.id.main_re, new BlankFragment());
beginTransaction.addToBackStack(null);
break;
}
beginTransaction.commit();
// moveTaskToBack(true);
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/main_re"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/frg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="跳转"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="248dp"
tools:layout_editor_absoluteY="295dp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>