androidandroid-support-libraryandroid-snackbarfloating-action-button

Snackbar half width on tablet


I have problem with setting Snackbar on tablet (API 22), on phones (API 23 and 22) it works fine (from edge to edge), even when horizontal. Result is such Snackbar as below:enter image description here

FloatingActionButton (support library) also doesn't move (when on phone it does).

My layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/snackParent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="@dimen/margin_fab"
        android:layout_marginRight="@dimen/margin_fab"
        app:pressedTranslationZ="12dp" />
</android.support.design.widget.CoordinatorLayout>

And using in MainActivity

private void showMessage(String msg) {
    if(snackParent != null) {
        snackbar = Snackbar.make(snackParent, msg, Snackbar.LENGTH_SHORT);
        snackbar.setAction("OK", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.show();
    }
}

I have only other resources file with dimensions (fab margin) for tablets (w820dp), styles folder is same between phone and tablet. I have also tried invalidating Android Studio cache. I use com.android.support:design:23.0.1 targetSdkVersion=23 and compileSdkVersion=23, buildToolsVersion=23.0.1.


Solution

  • I think this is the default behavior of snackbar on tablets. check this out .

    enter image description here