When using setDuration() for a Toast, is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG
?
相关问题
- 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 know the answer is quite late .. I had the very same issue and decided to implement my own version of bare bones Toast , after looking into android's source code for toast .
Basically you need to create a new Window manager , and show and hide the window for the desired duration duration using a handler
After initialization of the layout you can use your own hide and show methods
Now all you need is to add two runnable threads which calls the handleShow() and the handleHide() which you could post to the Handler.
and the final part
This was a quick and dirty implementation .. Have not taken any performance into consideration .
This text will disappear in 5 seconds.
Edit: As Itai Spector in comment said it will be shown about 3.5 seconds, So use this code:
As mentioned by others Android Toasts can either be LENGTH_LONG or LENGTH_SHORT. There is no way around this, nor should you follow any of the 'hacks' posted.
The purpose of Toasts are to display "non-essential" information and due to their lingering effect, messages may be put far out of context if their duration exceeds a certain threshold. If stock Toasts were modified so that they can display longer than LENGTH_LONG the message would linger on the screen until the application's process is terminated as toast views are added to the WindowManager and not a ViewGroup in your app. I would assume this is why it is hard coded.
If you absolutely need to show a toast style message longer than three and a half seconds I recommend building a view that gets attached to the Activity's content, that way it will disappear when the user exits the application. My SuperToasts library deals with this issue and many others, feel free to use it! You would most likely be interested in using SuperActivityToasts
Here is a very simple method which worked for me:
for (int i=0; i < 3; i++) { Toast.makeText(this, "MESSAGE", Toast.LENGTH_SHORT).show(); }
The duration of LENGTH_SHORT is 2 seconds and LENGTH_LONG is 3.5 seconds, Here the toast message will be shown for 6 Seconds since it is enclosed in a for loop. But a drawback of this method is after each 2 sec a small fading effect may arise. but it is not much noticeable. Hope it is helpful
I know I am a bit late, but I took Regis_AG's answer and wrapped it in a helper class and it works great.
In your application code, just do something like this:
A very simple solution to the question. Twice or triple of them will make Toast last longer. It is the only way around.