I'm trying to show a snackbar (via appcompat) to display a message to the user. It works perfectly fine on phones, however on tablets I'm getting
and
The code I'm using to generate the snackbar is
Snackbar.make(mHomeContainer, R.string.rate_snackbar, Snackbar.LENGTH_LONG)
.setAction("Rate", ...)
.show();
Any guidance on how to make this snackbar centered would be greatly appreciated
<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>
You need to use the CoordinatorLayout in order to make this happen. Here is an article that describes how to do that. Additionally you will likely need to now provide layout files that you want to use for non-tablets vs. tablets so that you can retain full-width for your phones. This is also the layout component that you need to use if you use a combination of FAB, app bar and Snackbar.
In v22.2.0 of Design Support Library, Snackbar's default gravity was just Gravity.BOTTOM.
In v22.2.1 this issue was fixed: https://code.google.com/p/android/issues/detail?id=176383
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With