android - AppCompat Snackbar 不以平板电脑为中心

标签 android material-design android-appcompat

我正在尝试显示一个 snackbar (通过 appcompat)以向用户显示一条消息。它在手机上工作得很好,但是在平板电脑上我得到了

portrait

landscape

我用来生成 snackbar 的代码是

Snackbar.make(mHomeContainer, R.string.rate_snackbar, Snackbar.LENGTH_LONG)
        .setAction("Rate", ...)
        .show();

任何关于如何使这个 snackbar 居中的指导将不胜感激

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/status_bar"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/main"
        android:elevation="8dp"/>

    <include layout="@layout/toolbar" />

    <RelativeLayout
        android:id="@+id/home_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true" />

        <ListView
            android:id="@+id/home_search_list"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#88000000"/>

    </RelativeLayout>
</LinearLayout>

<include layout="@layout/navigation_list" />

</android.support.v4.widget.DrawerLayout>

最佳答案

您需要使用 CoordinatorLayout 才能实现这一点。这是一个 article描述了如何做到这一点。此外,您现在可能需要提供要用于非平板电脑与平板电脑的布局文件,以便您可以为手机保留全宽。如果您结合使用 FAB、app bar 和 Snackbar,这也是您需要使用的布局组件。

关于android - AppCompat Snackbar 不以平板电脑为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30939485/

相关文章:

Android:CoordinatorLayout 和 SwipeRefreshLayout

android - 工具栏上的溢出按钮更改颜色

java - Android:TextInputLayout 不会将提示居中

android - 从 Android 中的图像创建视频文件

html - 如何让我的 Material Design 图标字体正确显示?

android - AppBarLayout 并不总是在向下滚动时重新进入

Android令人沮丧的网络错误

javascript - Google Material Design - 禁用开关

android getSupportActionBar() 在 fragment 中返回 null

android - Lollipop 上的工具栏高度太大