0

I'm trying to show a Popup message covering a part of a activity below it, but still want to enable the user to interact with activity, without dismissing the popup.

For example: "No Internet" message, but a part of application still working.

It can be an activity, or a dialog, but the activities below it should still receive user clicks.

I succeed to achieve this by including the same XML in several activities and apply common logic; but want to make it an independent UI unit

David Papirov
  • 121
  • 1
  • 5
  • 10
  • 1
    DialogActivity...? – Abbas Jul 11 '17 at 10:52
  • Does it leave the user to tap something below it, without dismiss it? – David Papirov Jul 11 '17 at 10:54
  • 1
    you can create a custom View which is initially hidden but appears only after certain action. – Payal Jul 11 '17 at 11:01
  • I have multiply activities, but do not want to include the view inside their XML (or programmatically), also when open another activity and going back this view will be re-shown, and need special logic in onResume(). That's what I currently wrote, but want to make independent topmost popup code – David Papirov Jul 11 '17 at 11:07

1 Answers1

1

You should use Snackbar for this purpose. For use of snackbar refer Adding an Action to a Message

OR

If you need to add a view independent of the application scope then you might try adding view directly to window like

patilmandar2007
  • 322
  • 2
  • 11
  • "They *automatically disappear* after a timeout or *after user interaction elsewhere on the screen*, particularly after interactions that summon a new surface or activity. Snackbars can be swiped off screen." But I need 1) to keep it visible, 2) disable user to dismiss it 3) enable user iteration with the rest of application window – David Papirov Jul 11 '17 at 11:02
  • And to pin it to screen-top – David Papirov Jul 11 '17 at 11:10
  • 1
    Snackbar is still the optimal solution. 1) Keep it visible -> Set length to indefinite 2) Disable dismiss: https://stackoverflow.com/questions/34031476/how-to-disable-snackbars-swipe-to-dismiss-behavior 3) Interaction is enabled by default – andras Jul 11 '17 at 11:22
  • Thanks, I'm checking. How to pin it to the window top? – David Papirov Jul 11 '17 at 11:34
  • But the snackbar will be referenced to the parent activity, isn't it? What will happen when user navigates to another activity? and goes back? I need something independent in the application scope – David Papirov Jul 11 '17 at 11:37
  • 1
    If you need to add a view independent of the application scope then you might try adding view directly to window. You can refer [this](https://stackoverflow.com/questions/19976701/add-a-view-on-top-of-all-the-activities) link – patilmandar2007 Jul 13 '17 at 08:40
  • Thank you, nice advice! But still the activity under the view does not receive user clicks – David Papirov Jul 13 '17 at 12:45
  • @patilmandar2007, your code in [link](https://stackoverflow.com/questions/37138546/when-adding-view-to-window-with-windowmanager-layoutparams-type-system-overlay) make it working. Add it as answer to this post – David Papirov Jul 13 '17 at 12:56