gpt4 book ai didi

android - 将 Snackbar 移到 bottomNavigationView 上方

转载 作者:行者123 更新时间:2023-11-30 04:58:18 25 4
gpt4 key购买 nike

想把我的 snackbar 移到 bottomnavigationview 上面

<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()
}

但是 snackbar 也会从屏幕底部显示

最佳答案

在 BottomNavigationView 上方添加一个 Layout

例子:

<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();

关于android - 将 Snackbar 移到 bottomNavigationView 上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com