First of all, I know this has been asked before: Button in custom Android Toast?.
This is nearly an exact duplicate, but I think that it warrants a new question based on the fact that it's been used in apps, namely Gmail for ICS (it appears when you delete a message).
The linked question says that it's not possible to include a button in a Toast because Toasts cannot be focused. Is this wrong, outdated, or did Gmail find a way around it?
The Gmail undo bar is't a toast, here is how Google did it
http://code.google.com/p/romannurik-code/source/browse/misc/undobar/src/com/example/android/undobar/UndoBarController.java
I guess this answers your question.
What you're referring to is not a Toast but what Google has dubbed a Snackbar. See the Material Design guidelines.
You can find several implementations of this on GitHub. Some also go by the name of UndoBar
Currently, the most extensive, popular, and active one seems to be Snackbar by nispok, which I also happen to be using.
If you want a button in a toast, its better you quit that idea. But you can use dialogs in place of toast. Using dailogs, you will be able to display whatever you want (same function as a toast would do). Also in the dailog, you could set buttons.
Gmail on iOS does provide a toast and it is a much better solution than interrupting the user flow with a dialog.
![Toast style message in Gmail for iOS][1] [1]: http://i.stack.imgur.com/LWClq.jpg
If you use this option, make sure the toast is displayed long enough for the user to tap undo if needed. So 5 seconds as opposed to 2.5-3 seconds in a info-only toast.
The other example cited by CommonsWare is the inline feedback which is shown after a swipe gesture. This is not a toast- but it is also a great way to provide feedback that an action has been performed.
I have extended the UndoBar mentioned by #Hazem (link) and made it more generic so that it can be used for other actions also. You can have a look here.
Related
I am re-pharsing my question to avoid negative points. I am aware of web view, dialogs, popups, notifications. if you have some other ideas please let me know.
I am working on a very big android application, in which I have to add some popup kind of thing, which tells the user what we have updated for this version. Kind of like, what bugs are fixed or whats new things are added.
The window have to be populated once or twice and it have to have user interactions, like click on the link, or contact us, or click on the image to go to some page inside the app. Please let me know any good ideas.
You definitively should give a look to the AlertDialog class
http://developer.android.com/reference/android/app/AlertDialog.html
This is basically the class used to display a message and get the ok/cancel/anything answer from the user. But it's customizable and you can make more or less what you want according to which button is pressed by the user.
I would like to display a message to the user for some asynchronous event. For example for an alarm expiration. I would like to display a popup or dialog that is displayed over any activity is the foreground at the moment (and this can be some other application activity) leaving the current activity in the backgound.
Is there a way to do so in Android?
First off, you will be told that this is a bad thing to do, that it is against the Android way of doing things. Users do not like this. And that the Notification area is much better way to do this.
That said... there are ways to accomplish this...
A Toast will display no matter which activity is on the screen. So you could set up a background thread (or better a Service) that will display your information in a Toast. This might be good enough for you.
You may find it useful looking at some Toast source code here.
Also here is a nice page on how to create a custom Toast layout by replacing the default View with one of your own. (I have not done this, but it looks quite interesting):
Custom Toast Alert on androidexample.com
The alternative is much more difficult, and is to display a System Overlay window. Unfortunately you have to do quite a lot of work to get these set up properly.
Here are a few related questions that I used to get it working:
Creating a system overlay window (always on top)
System overlay android 4.0
How to create a system overlay in Android which allows interaction with the windows below it?
Each of these has links to many others - there are loads of System Overlay questions on here.
But things to remember:
In the old days, you could put a system overlay on top, and send
touches through to the activity below. This is no longer possible,
and so a lot of the answers are now out of date.
You may need to
play around with the flags in the provided examples to get exactly
the effect you are aiming for. Not all the examples use the same
flags, so there are some subtle differences in how each solution
works.
Then again, I also believe that the Notification area is a much better UI pattern to use, so I do recommend you try that first. It is easier to do, and most of us expect that type of behaviour rather than a pop-up.
The problem with a pop-up, is that it might interrupt a movie I'm watching. Or a game I'm playing.
Yes, i had created two dialog for income event for background and foreground
I've got a problem with the system default toasts in my application. In the config options I let my users to choose if they want to add shortcuts for every point of entry of my activities, and this create a bunch of shortcuts in the home menu.
Since I am changing these shortcuts constantly via cloud api and some tricks, I've decided to delete and create again the shortcuts in the background every time the user logs in the applications. So here's the point, the user gets spammed by the default system toast "Deleting 'Name' shortcut" and "Creating 'Name' shortcut". Since I'm deleting&creating 3 to 5 shortcuts, this is such a big spam.
I wanted to hide this default toasts or maybe change its colors or whatever in order to don't interfere with my app, because they take a long time to disappear.
I've been trying to find a workaround for this but no way. Any idea/suggestion will be very appreciated.
I've already seen Dianne Hackborn answer about this topic, but I wanted to know if there's any viable option.
Thanks and have a nice day.
I'm developing an app that intercepts toast messages and displays them in a custom view.
The interception part is easily implemented using the AccessibilityService.
The tricky part is how to suppress the toast messages from appearing (or at least make them invisible). I know (to the best of my understanding) that this is not possible in normal circumstances.
But does anyone know any hacks that would allow me to suppress the toasts from appearing or make them invisible?
Would it be possible with root permission?
Note: I'm relatively new to programming. Nonetheless, I had a look at the android source code for Toast.java (link). Would it be possible to intercept the show() method or any other relevant method to stop them from appearing (maybe with root permission)?
According to Dianne Hackborn here, you can't. Yes, I realize that post is over four years old, but I haven't seen anything in the SDK since to overcome that.
Yes, you can use an accessibility service to detect toasts, but that's only so you can do something in addition, like TTS, not to stop them.
It would be a bad day if you could. For example, junk apps that pastes shortcuts on your desktop. Root apps that require SuperUser. In both cases, a toast pops up to let you know that something out of the ordinary is happening. That's a good thing, and if I ever found an app that was suppressing toasts, it would be gone instantly.
Moral issues aside, you could do this if you changed the OS source and compiled it on your own, but it would still only work for users that had that particular ROM installed.
As another option, have you tried creating your own Toast instead? You can give it a custom View, and if it's timed right, it will show up just after the normal one. Then it would overlap and you won't see the first. I'm not sure how feasible it is, but it's a thought.
i asked so many question regarding my title but i could not get my proper answer till yet.I need to implement androd's menu feature in my application ie when we goes to gallery in android phone, when we press menu than it comes with lots of option like share...etc.My question is can i implement same menu feature in my application? It is possible or not?
Thanks
To implement a "Share" feature, all you need to do is use createChooser() and an ACTION_SEND Intent.
Here is a blog post covering the technique.
If I am understanding your question you want to know if you can duplicate the feature of tapping on the menu button on the phone and having it pull up an options menu that you can then share via, gmail or some other posting medium?
If this is correct then I would have to say I would assume that you could duplicate this feature.
In short YES!
If you are wondering how you are to do this then I would start at here http://developer.android.com/guide/topics/ui/menus.html
Droidnova .com (I posted it like this because as a new user I can only post one link) also has a good little how to on menu's.
I would also like to add that this is my first time posting on stackoverflow so please let me know if this was a good post or what I should do next time.
Thanks,
Bactos