简体   繁体   English

Snackbar 显示在导航栏中,放在上面

[英]The Snackbar is showing in the navigation bar, put it above

I am working in a project with dynamic modules.我正在一个带有动态模块的项目中工作。 Where we a navigation bar that is in the Dashboard module.我们在 Dashboard 模块中的导航栏。 But I working in another module, that the view is a fragment tied to the Dashboard Activity.但是我在另一个模块中工作,该视图是与仪表板活动相关联的片段。 And I want to show an snackbar, but my problem is that the snackbar instead of showing at the bottom of the fragment view is showing in the navigation bar (I attached photos).我想显示一个小吃店,但我的问题是小吃店而不是显示在片段视图的底部,而是显示在导航栏中(我附上了照片)。 I have tried several things but i don't know how to solved.我已经尝试了几件事,但我不知道如何解决。

This is how i creating the snackbar:这就是我创建小吃店的方式:

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

This is my layout of the fragment:这是我的片段布局:

<?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没有小吃店的应用程序图像

You can set margin to your Snackbar like this:您可以像这样为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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM