0

I just want to know if there's a way of applying PopupWindow.setWindowLayoutType() on API < 23. Based on the documentation, it can only be use on API 23 and above. But is there a hack or workaround?

I have a custom toast. I want this toast to dismiss/cancel whenever the user tap/click it. But unfortunately, There's no way of interacting to the toast. I tried setting an onClickListener but got no luck. So I decided to use PopupWindow and adding a handler to dismiss the PopupWindow after 3sec. Everything is fine except that when navigating to the next screen, the PopupWindow also got dismissed. Then I applied setWindowLayoutType and set it to setWindowLayoutType(WindowManager.LayoutParams.TYPE_TOAST);. It works but only on API 23 and above.

Any ideas on how can I apply this on lower API versions? Thanks.

ps. I don't want to use third party libraries.

mgcaguioa
  • 1,443
  • 16
  • 19
  • When you say it "works but only on API 23 and above", do you mean you tried it on a lower API version and it didn't work, or do you mean you're just going by the documentation? 'cause I think the docs might be wrong about when that was added. – Mike M. Oct 21 '16 at 04:06
  • I tried it already but the popupWindow got dismiss when activity finished. unlike on api23 above, it still stays (like a toast). – mgcaguioa Oct 21 '16 at 04:13
  • Oh, OK, so you did try it, and it just didn't work as you were expecting. Yeah, the docs are wrong for that method. If it had just been added in API 23, then your app would've crashed when calling it In a lower API, but it was added a long time ago; in 2010, looking at the source. – Mike M. Oct 21 '16 at 04:16

0 Answers0