简体   繁体   中英

Android Clickable Banner Notification

What would be a good way of creating a banner that appears over an activity and/or fragment that shows only for 2-3 seconds then disappears. I also want it to disappear when simply clicked on. I want it to hold an image.

It seems like it could be done via a heads-up notification correct? I would just create a custom notification lay out and make it so it doesn't do anything when clicked on so it just disappears from my current view.

Would that be the right approach?

if i understand the requirements correctly, You simply want a little view that will show up and float over everything else on the screen.

In ur main activity u can include a layout as the last element in the file ie at the bottom since layout files are parsed from top to bottom so the element that is at the bottom is actually on top of everything when the view is rendered. its almost like an overlay. Assuming that ur main activity is the one that handles all the fragments in the application and is always running.

Optionally u can include that layout in every layout file that needs a view like that to show up and just show it when needed almost like the snack bar at the bottom of the screen.

If u would like it to slide in like a heads-up notification then u can always add a translateAnimation to the view when it u want to show it and it will look like a popup notification. What u do in the clicklisteners is not controlled by the view that u have build.

I would also recommend creating a custom view that way u can have listeners that fragments or activities can implement in order to create custom actions for the notifications depending on the data that is part of the notification.

As for making it disappear have a timer job running that will make it disappear after 2-3 seconds.

Let me know if u would like any clarification since I am unsure if it makes sense since I have not provided any examples.

您应该在自己的用例中使用headsup通知,因为它完全符合您的需求。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM