Reputation: 5593
This post says:
When you add a
FloatingActionButton
as a child of yourCoordinatorLayout
and then pass thatCoordinatorLayout
to yourSnackbar.make()
call - instead of the snackbar displaying over the floating action button, theFloatingActionButton
... automatically move upward as the snackbar animates in and returns to its position when the snackbar animates out
I've made exactly as described there but FAB does not move upward. (Snackbar can be swiped out, it means that CoordinatorLayout knows about it.)
Upd
Layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/action_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.ActionBar"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/action_toolbar"/>
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?attr/actionBarSize"
android:background="@color/theme_primary_darker_color"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/toolbar_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_navigation_white_24dp"
android:layout_margin="16dp"
android:visibility="gone"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchor="@id/action_toolbar"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="12dp"/>
</android.support.design.widget.CoordinatorLayout>
Code:
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content);
...
Snackbar.make(mCoordinatorLayout, R.string.waypoint_deleted, Snackbar.LENGTH_LONG).show();
Upvotes: 4
Views: 2438
Reputation: 1
I was having the issue where the fab would not return to its original location after the snackbar disappeared. Make sure Animator duration scale is turned on. A good default is 1x.
The setting can be found in:
This setting along with other animation settings were turned off on one of my emulators. Turning it back on got the fab working correctly.
Upvotes: 0
Reputation: 107
I had a similar problem where my fab button wouldn't move down. Took me a while but it was because I had animations off in the developers option. Hope you got it working even though I know this post is a bit dated.
Upvotes: 0
Reputation: 29416
I've written sample project based on the code you posted and I had to change three things to make FloatingActionButton
aware of the Snackbar
.
false
- looks like Proguard strips out some annotations (e.g. Behaviour
s) which are necessary to coordinate FloatingActionButton
. You'll need to add some Proguard rules in your release build where Proguard is enabled.FloatingActionButton
as a first argument of Snackbar.make()
, not the CoordinatorLayout
itself as mentioned here.app:layout_anchor="@id/action_toolbar"
and replace app:layout_anchorGravity="bottom|right|end"
with the app:layout_gravity="bottom|right|end"
from the layout (not sure if it's suitable for you).If it doesn't work for you, you can try to write your own Behavior
class as described in the article mentioned above.
Upvotes: 8