BottomNavigationView后面的片段中的底页

问题描述 投票:0回答:1

在我的片段中,单击一个按钮时,我需要显示一个底部对话框,但该对话框必须从底部导航栏的后面出现。类似的问题已经解决here,但由于某些压力,我需要仅通过扩展BottomSheetDialogFragment来创建底部工作表。

activity_main.xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">   

    <fragment
        android:id="@+id/navigationHost"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigation"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/navigation" />    

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="61dp"
        android:layout_marginStart="14dp"
        android:layout_marginEnd="14dp"
        android:layout_marginBottom="30dp"
        android:background="@drawable/bg_bottom_nav_rounded"
        app:itemIconTint="@color/selector_bottom_navigation_text"   
        app:itemTextColor="@color/selector_bottom_navigation_text"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/navigationHost"
        app:menu="@menu/dashboard_navigation_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>    

fragment_home.xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray">

    <Button
        android:id="@+id/openBottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>    

FragmentHome.kt

class FragmentHome : Fragment(R.layout.fragment_home) {
    private val binding by viewBinding(FragmentHomeBinding::bind)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.openBottomSheet.setOnClickListener {
            val bottomSheetDialog: BottomSheetDialog = BottomSheetDialog()
            bottomSheetDialog.show(requireActivity().supportFragmentManager, "TEST")
            bottomSheetDialog.enterTransition
        }
    }
}    

BottomSheetDialog.kt

  public class BottomSheetDialog extends BottomSheetDialogFragment {
        @Nullable
        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            super.onCreateView(inflater, container, savedInstanceState);
            return inflater.inflate(R.layout.bottomsheet_login, container, false);
        }

        @Override
        public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
        }
    }

UPDATE:Screenshots

android kotlin bottomnavigationview bottom-sheet android-bottomnavigationview
1个回答
0
投票

这是BottomSheetSnackbar的常见问题,您需要在CoordinatorLayout上添加parent作为activity根视图。将CoordinatorLayout作为父母,并在其中放置ConstraintLayout

© www.soinside.com 2019 - 2024. All rights reserved.