Переместить снэк-бар над нижней панелью навигации - PullRequest
1 голос
/ 07 ноября 2019

Хотите, чтобы моя закусочная была выше нижней навигационной панели

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activityRootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbarView"
                android:layout_width="match_parent"
                android:layout_height="@dimen/action_bar_size"
                android:background="@color/color_primary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        </FrameLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomNavigationLayout"
        android:layout_below="@+id/appBarLayout" />

    <LinearLayout
        android:id="@+id/bottomNavigationLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <View style="@style/FullDivider" />

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:itemBackground="@android:color/white"
            app:itemIconTint="@drawable/selector_bottom_bar_item"
            app:itemTextColor="@color/blue"
            app:labelVisibilityMode="unlabeled"
            app:menu="@menu/main_navigation" />
    </LinearLayout>

    <com.mandarine.features.security.UnlockAppInputView
        android:id="@+id/unlockAppInputView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" />
</RelativeLayout>

В MainActivity напишите что-то вроде этого:

container?.let {
    Snackbar.make(it, "No internet connection!", Snackbar.LENGTH_LONG).show()
}

Но закусочная также отображается с экрана экрана

Ответы [ 3 ]

0 голосов
/ 07 ноября 2019

Я считаю, что проблема в findSuitableParent функции. Как вы можете видеть на 232 строке, ваш контейнер используется как запасной вариант, но затем будет найден корневой вид. Попробуйте изменить контейнер на CoordinatorLayout, и это решит проблему.

0 голосов
/ 07 ноября 2019

Решите мою проблему следующим решением:

private fun showNetworkMessage(isConnected: Boolean) {
    if (!isConnected) {
        val snack = Snackbar.make(
            findViewById(R.id.container),
            this.getText(R.string.warning_no_internet_connection), Snackbar.LENGTH_LONG
        )
        val params = snack.view.layoutParams as FrameLayout.LayoutParams
        params.setMargins(0, 0, 0, this.resources.getDimension(R.dimen.action_bar_size).toInt())
        snack.view.layoutParams = params
        snack.show()
    }
}

Где вы можете видеть, что я не использовал CoordinatorLayout.

0 голосов
/ 07 ноября 2019

Добавьте один макет выше BottomNavigationView

Пример:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:id="@+id/myLayout"
 android:layout_above="@id/bottomNavigationView">
</android.support.design.widget.CoordinatorLayout>

, затем в коде Java используйте:

final View viewPos = findViewById(R.id.myLayout);    
Snackbar.make(viewPos, R.string.snackbar_text, Snackbar.LENGTH_LONG)
                            .setAction(R.string.snackbar_action_undo, showListener)
                            .show();
...