Search code examples
androidfloating-action-buttonshared-element-transition

Floating action button blink after closing activity using Shared Element Transition


I have an issue with Shared Element Transition. When I return to MainActivity from DetailActivity, FAB blinking Gif example

I used this sample project. For shared element transition I made:

  1. Enabled Window Content Transitions in styles.xml
    <item name="android:windowContentTransitions">true</item>
  2. Assign a common transition name to the shared elements in both layouts. android:transitionName="image"
  3. Started the target activity by specifying a bundle of those shared elements and views from the source
    holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = v.getContext(); Intent intent = new Intent(context, CheeseDetailActivity.class); intent.putExtra(CheeseDetailActivity.EXTRA_NAME, holder.mBoundString); MainActivity activity = (MainActivity) context; ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, new Pair<>(holder.mView.findViewById(R.id.avatar), "image")); ActivityCompat.startActivity(context,intent, options.toBundle()); } });
    And when i press back button, FAB from detail Activity blinks in Main activity.
    I did not find a similar problem, so thanks for any help!

Solution

  • I fixed it by hiding FAB before close Activity.
    In onBackPressed() and in home button onClick i pasted:

        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) myFab.getLayoutParams();
        params.setBehavior(null);
        myFab.requestLayout();
        myFab.setVisibility(View.GONE);
    

    Maybe it will be useful for someone.