6

I'm using roughike's BottomBar 2.0: https://github.com/roughike/BottomBar/

When I display a SnackBar, it shows up on the BottomBar itself.

I want it to be drawn above the BottomBar.

activity_main.xml:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/here"
        android:background="#fff">

        <FrameLayout
            android:id="@+id/contentContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottomBar">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Three Buttons Bar"
                android:id="@+id/textView"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:textColor="@color/colorPrimary"
                android:textSize="35sp" />

        </FrameLayout>

        <com.roughike.bottombar.BottomBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            app:bb_tabXmlResource="@xml/bottombar_tabs" />
    </RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

MainActivity.java:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelected(int tabId) {
                switch (tabId) {
                    case R.id.recent_item:
                        Snackbar.make(findViewById(R.id.main_activity), "Recent Item Selected", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.favorite_item:
                        Snackbar.make(findViewById(R.id.main_activity), "Favorite Item Selected", Snackbar.LENGTH_LONG).show();
                        break;
                    case R.id.location_item:
                        Snackbar.make(findViewById(R.id.main_activity), "Location Item Selected", Snackbar.LENGTH_LONG).show();
                        break;
                }
            }
        });
    }
}

Screenshots:

BottomBar Only BottomBar hidden when SnackBar appears

Is anything wrong with the layout file??
What am I missing??

I also checked this: Move snackbar above the bottom bar, but it didn't help..

EDIT:

I tried as Abtin said:

Snackbar.make(bottomBar, "Location Item Selected", Snackbar.LENGTH_LONG).show();

and

<com.roughike.bottombar.BottomBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            app:bb_tabXmlResource="@xml/bottombar_tabs"
            app:bb_behavior="underNavbar"/>

Now it has become like this:

Bottom Bar with extra space below That space filled by Snackbar

As you can see, there's this unused space below the BottomBar when I set app:bb_behavior="underNavbar", which is not I want..

Community
  • 1
  • 1
Gokul NC
  • 1,111
  • 4
  • 17
  • 39

6 Answers6

10

With the new material design, Snackbars have a new look .. you can show snackbar above BottomBar with this line:

Snackbar snackbar = Snackbar.make(parentView, text, duration);
snackbar.setAnchorView(bottomBar);

This will do the work.

Ansshkki
  • 760
  • 8
  • 14
6

You should create CoordinatorLayout in xml, from his bottom you wish will be shown SnackBar and give id of the CoordinatorLayout as id of View at fun. make of SnackBar.

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/viewSnack"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp"/>

inside activity:

Snackbar.make(findViewById(R.id.viewSnack), "Text of the SnackBar", Snackbar.LENGTH_LONG).show();
Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
Taras Okunev
  • 410
  • 6
  • 9
0

try changing the view you pass to the snackbar.

Snackbar.make(findViewById(R.id.contentContainer), "Recent Item Selected", Snackbar.LENGTH_LONG).show();    
Matthew Shearer
  • 2,715
  • 3
  • 23
  • 32
0

Depending on how the coordinator layout behavior is implemented you may have to pass the bottom bar view itself to the first argument of Snackbar.make().

Snackbar.make(bottomBar, "Location Item Selected", Snackbar.LENGTH_LONG).show();

The other possibility is that you are missing an attribute for app:bb_behavior on the bottombar widget in the layout.

Abtin Gramian
  • 1,630
  • 14
  • 13
0

I switched from the Roughike's BottomBar 2.0 to Roughike's BottomBar 1.4..

Now it's working as intended (ofcourse the code changes)..

I also tried AHBottomNavigation, it's cool and also working as intended..

I'm not marking this as Answer, since it doesn't answer the question ;)

Gokul NC
  • 1,111
  • 4
  • 17
  • 39
  • How did you get it working with AHBottomNavigation? I am using it too, but the snackbar doesn't show above it, but in front of it :( – hildegard Jun 02 '17 at 10:42
0

It is very simple ! in your activity_main.xml declare an ID for your root layout :

<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linerMain">

then in view field of Snackbar's make do as bellow:

Snackbar snackbar = Snackbar.make(findViewById(R.id.linerMain),"name",Snackbar.LENGTH_INDEFINITE);
sina akbari
  • 618
  • 6
  • 7