【问题标题】:The Snackbar is showing in the navigation bar, put it aboveSnackbar 显示在导航栏中,将其放在上方
【发布时间】:2020-11-23 14:41:16
【问题描述】:

我正在一个带有动态模块的项目中工作。我们在仪表板模块中的导航栏。但我在另一个模块中工作,该视图是与仪表板活动相关的片段。我想显示一个快餐栏,但我的问题是导航栏中显示的是快餐栏而不是显示在片段视图的底部(我附上了照片)。我尝试了几件事,但我不知道如何解决。

这就是我创建小吃店的方式:

            Snackbar.make(it, "test", Snackbar.LENGTH_INDEFINITE).show()

这是我的片段布局:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

    <TextView
        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"
        app:layout_constraintBottom_toBottomOf="parent"
        android:textAlignment="center"
        android:text="Welcome"/>

 </androidx.constraintlayout.widget.ConstraintLayout>
 </ScrollView>

The image of the Snackbar

The image of the app withour snackbar

【问题讨论】:

  • BottomNavigationBar上方创建一个空白CoordinatorLayout,将其height至少设为100dp,并将此布局作为parentLayout传递给SnackBar。肯定会奏效。示例答案here.

标签: java android android-layout kotlin


【解决方案1】:

您可以像这样为 Snackbar 设置边距:

Snackbar snack = Snackbar.make(coordinatorLayout, "test", Snackbar.LENGTH_LONG);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) 
                                         snack.getView().getLayoutParams();
params.setMargins(0, 0, 0, bottomBarHeight);
snack.getView().setLayoutParams(params);
snack.show();

【讨论】:

    猜你喜欢
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多