【问题标题】:Snackbar inside layoutSnackbar 内部布局
【发布时间】:2015-12-10 04:57:27
【问题描述】:

是否可以在布局中显示 Snackbar 消息,例如在 RelativeLayout 中显示而不是在屏幕底部显示?

我尝试将引用视图用于 RelativeLayout,但它不起作用。

Snackbar.make(relativeLayoutView, snackbarText, Snackbar.LENGTH_LONG).show();

【问题讨论】:

    标签: android android-snackbar snackbar


    【解决方案1】:

    您可以通过在相对布局中创建一个新布局 CoordinatorLayout 并将自定义宽度和高度设置为 CoordinatorLayout 布局来做到这一点。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.CoordinatorLayout 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="100dip">
    
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:layout_margin="16dp"
                android:src="@drawable/add"
                app:layout_behavior="com.demotest.FloatingActionButtonBehavior" />
    
        </android.support.design.widget.CoordinatorLayout>
    </RelativeLayout>
    

    【讨论】:

      【解决方案2】:

      我认为您不能在屏幕上的任何位置显示快餐栏,只能在底部显示。根据标准,它应该在底部。

      根据文档所说,

      “Snackbars 提供有关操作的轻量级反馈。它们在​​移动设备上的屏幕底部和较大设备上的左下方显示一条简短消息。”

      https://developer.android.com/reference/android/support/design/widget/Snackbar.html

      如果你还想这样做, 结帐,

      How can you adjust Android SnackBar to a specific position on screen

      How do I change an Android Snackbar's initial alignment from bottom to top?

      【讨论】:

        猜你喜欢
        • 2017-05-10
        • 2019-09-18
        • 2013-08-27
        • 2015-12-03
        • 1970-01-01
        • 1970-01-01
        • 2016-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多