Search code examples
androidbuttonoverlayvisible

Android overflow button overlay / always visible


I'm trying to get a button to be always on top (just when the application is active, not like the facebook messenger one).

How do I accomplish that?

Since i have a main activity, which switches out the fragments, I can't create the button in the fragments, and it seems that I can't initialise a button in the main activity that will be on top of those fragments.


Solution

  • You can put the button and other views of activity_main.xml inside a FrameLayout. Put everything else except the button inside a RelativeLayout(or whatever you want) and then put the button as the last element of the parent FrameLayout.

    Now set the content area for fragment somewhere inside that RelativeLayout so that your fragment will be replaced in that area only. By doing this the button will be displayed on top of your fragments too. Hope it helps.