Adding a shared floating action button to two existing activities

616 Views Asked by At

I'm working on an app that is already in production, it has multiple activities. The designers now want to add a Floating Action Button which is anchored to the bottom-right of two of our activities (possibly more in future). The FAB needs to remain at the same spot when the two activities transition between each other.

I know I can use shared element transition to achieve this, but the problem is we are using overridePendingTransition() to add a sliding animation when transitioning between the two activities, and that sliding animation gets broken when I use shared element transition as it gets overridden by the scene transition animation.

Has anyone had to do something similar?

To summarise, here are my requirements:

  1. two activitie transition between each other using a sliding animation
  2. a floating action button is in both activities, in the same location
  3. the FAB needs to remain stationary at all times, including during the transition between the two activities
  4. the FAB can but doesn't need to respond to onClick events during transition (this is an acceptable limitation)
  5. I don't care how dirty the implementation is, but I would strongly prefer not to refactor into a single activity because both activities are quite complex as they are

Happy to provide any additional details if it helps. Thanks.

1

There are 1 best solutions below

2
Rishav Chudal On

Actually, I don't have similar case to you. I am working on multiple fragments rather than activities. What you can do is create a base activity which implement the fab button and extend that base activity in the other two activities.

For the respective work of fab button in each activity, you can do that with the help of string in savedInstanceState i.e from Bundle.

Hope it helps!!