I have a need to show a minimally-intrusive non-blocking notification which is not tied to the activity it was shown in (like a Toast
) and which is clickable. Anyone have any idea whether or not this is possible? Unfortunately it appears Toast
notifications (custom or otherwise) are not clickable (i.e. setting an OnClickListener
on its views has no effect). And, correct me if I'm wrong, all the alternatives (AlertDialg
, PopupWindow
, Crouton
) show a notification which is tied to the activity it was shown in (i.e. they won't continue showing when the activity finishes). Any suggestions?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I think what you need is in fact a
PopupWindow
which can be seen here "http://developer.android.com/reference/android/widget/PopupWindow.html".Toasts have a very specific task, which is to inform the user, without any input from them. So instead of trying to extend the purpose of the Toast, use the PopupWindow which can be interacted with by the user.
You can use
PopupWindow
, add anonClickListener
and add ahandler
to auto cancel it after n times (just like the behavior of atoast
). Something like this:xml layout:
You are right, a
Toast
object has no way to be interacted with, but there are many libraries out there that will give you the same look and feel as a toast, but with some interactivity. The one I use is https://github.com/JohnPersano/SuperToastsA 'Dialog' type of activity will probably be your best bet.
In manifest:
And timeout the activity within the onCreate():
To display the dialog start it as with any other activity:
And it will show up and automatically go away after X seconds.
Such a popup will not be tied to the caller activity. In fact - it will not even require a caller activity. You can activate it (bad idea, but possible) even from a service.
You can implement basically any kind of sensitive (i.e. accepting user's clicks) interface you want to the ToastLikeActivity. Especially: you can make its exteriors transparent, giving it a dialog-likke looks.