I'm using this library to implement a floating action bar and I can't seem to find a way to move the button when a snackbar appears on screen. Is it even possible with that library?
A floating action button (FAB) is a circular button that triggers the primary action in your app's UI. This page shows you how to add the FAB to your layout, customize some of its appearance, and respond to button taps.
FAB is a natural cue for telling users what to do next. Research by Google shows that, when faced with unfamiliar screen many user rely on FAB to navigate. Thus, FAB is very useful as a signpost of what's important.
A floating action button represents the primary action in an application. Make floating action buttons positive actions like Create, Favorite, Share, Navigate, and Explore. Always think about the current screen before using FAB.
To anyone looking out for answer in future..
Coordinator Layout used as Parent Layout of Floating Action Button will handle the animation effect for you automatically.
The floating action button has a default behavior that detects Snackbar views being added and animates the button above the height of the Snackbar accordingly.
Floating Action Button Behavior
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/clayout"> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" android:src="@drawable/filter_icon" app:rippleColor="@color/colorGray" app:fabSize="normal" app:borderWidth="0dp"/> </android.support.design.widget.CoordinatorLayout>
Then our SnackBar code would use Coordinatorlayout[here clayout] as parentlayout like below:
Snackbar.make(clayout, "Click on row to know more details", Snackbar.LENGTH_LONG) .setAction("OK", new View.OnClickListener() { @Override public void onClick(View v) { } }).show();
Try usingandroid.support.design.widget.FloatingActionButton
and CoordinatorLayout
.
And then try this:
fabView = findViewById(R.id.floating_action_button_id); Snackbar.make(fabView, "Hi", Snackbar.LENGTH_LONG).show()
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