Нижний лист во фрагменте за BottomNavigationView - PullRequest
0 голосов
/ 16 июня 2020

В моем фрагменте при нажатии кнопки мне нужно показать диалоговое окно нижнего листа, но оно должно появиться из-за нижней панели навигации. Подобная проблема уже решалась здесь , но из-за некоторых напряжений мне нужно создать нижний лист, расширив только 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);
        }
    }

ОБНОВЛЕНИЕ:
Скриншоты

1 Ответ

0 голосов
/ 16 июня 2020

Это обычная проблема с BottomSheet или Snackbar, вам нужно добавить CoordinatorLayout как parent root представление на activity. Поместите CoordinatorLayout в качестве родителя, а внутри него поместите свой ConstraintLayout

...