nice~
<?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:ignore="MissingConstraints">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/teal_200"
android:tag="main"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/bottom"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/navigation"
/>
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="52dp"
app:singleSelection="true"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/button_bottom_navi_style"
android:text="首页" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_moments"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
style="@style/button_bottom_navi_style"
android:text="萌圈" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/button_bottom_navi_style"
android:text="+" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_shop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/button_bottom_navi_style"
android:text="商城" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_me"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/button_bottom_navi_style"
android:text="我的" />
</com.google.android.material.button.MaterialButtonToggleGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
<navigation 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:id="@+id/trees_of_block"
tools:ignore="UnusedNavigation"
app:startDestination="@id/btn_main">
<fragment
android:id="@+id/btn_main"
android:name="com.vily.home.fragment.MainFragment"
android:label="four"
tools:layout="@layout/fragment_main"/>
<fragment
android:id="@+id/btn_moments"
android:name="com.vily.home.fragment.MomentsFragment"
android:label="one"
tools:layout="@layout/fragment_moments"/>
<fragment
android:id="@+id/btn_shop"
android:name="com.vily.home.fragment.ShopFragment"
android:label="two"
tools:layout="@layout/fragment_shop"/>
<fragment
android:id="@+id/btn_me"
android:name="com.vily.home.fragment.MeFragment"
android:label="three"
tools:layout="@layout/fragment_me"/>
</navigation>
mInflate.bottom.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
if(isChecked && defalutCheckId!=checkedId) {
Log.i(TAG, "initListener: ---------xxxx");
if(checkedId==R.id.btn_add){
Log.i(TAG, "initListener: --------弹出框");
}else{
mNavController.navigate(checkedId);
}
group.findViewById(defalutCheckId).setSelected(false);
group.findViewById(checkedId).setSelected(true);
defalutCheckId = checkedId;
}
});
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fcv_fragment); mNavController = navHostFragment.getNavController(); defalutCheckId=R.id.btn_main;