1

As you see below, Google Translate can show a pop-up window when PROCESS_TEXT is received. (I am not asking for how to process this message.)

I want to do a similar thing but there are some problems. I created a pop-up window using TYPE_SYSTEM_ALERT. (I wanted to use TYPE_APPLICATION_OVERLAY, but a permission error kept happening.) How can I solve these problems and make a pup-up window just like that of Google Translate? I think this is not a weird requirements. Do you know any scaffolding, template or sample for this? I searched Google, but failed to find one.

  • With Google Translate's, you can press the back button to close it. Mine does not.
  • With Google Translate's, if you tap elsewhere (e.g., the shady part), it closes. Mine does not. I could get the "tap outside" event and close it, but only when FLAG_NOT_FOCUSABLE was set, but if that was set, I could not interact with it.

Google Translate

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • As you see, the window (Google Translate) is not from the application below (Chrome). Can DialogFragment be shown without an activity? – Damn Vegetables Aug 13 '17 at 00:54
  • 2
    It looks like that might be possible, kind of. I was curious, so I just ran a quick test on the device I have with me. If you set a `NoDisplay` theme on the `Activity`, you can still show a `Dialog`/`DialogFragment` from it. Calling `setCanceledOnTouchOutside(true)` would give the desired behavior. Another possibility would be to use a regular `Activity` with a translucent background, and just align that `View` to the top, with some paddings/margins. The `Activity`'s `onTouchEvent()` can be used to determine if a touch lands outside of the `View`. – Mike M. Aug 13 '17 at 01:09
  • Thank you. I have tried your second option, and I think I can get similar effects. I set the activity's theme to `@android:style/Theme.Translucent.NoTitleBar` and set a translucent background colour to the layout. By the way, is there a cleaner way to determine in `onTouchEvent` whether a widget (e.g., TextView) is clicked or the outside (layout) is clicked, other than calculating the X,Y myself? – Damn Vegetables Aug 13 '17 at 01:47
  • Not really. You don't need to calculate anything, though. You just need to compare the `MotionEvent`'s x,y to the outermost `View`'s left, top, right, and bottom. – Mike M. Aug 13 '17 at 02:26
  • @DamnVegetables, i am looking for similar popup, hoping if you can extend your guidance to help achieving the same result. – Furqan Safdar May 14 '18 at 13:18

0 Answers0