目标效果:
首先导入包,build.gradle页面加入下边两句话:(后边的28.0.0根据自己的版本来改)
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
fragment_one.xml页面:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OneFragmenrt">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="one" />
</FrameLayout>
fragment_two.xml页面:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TwoFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="