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've coded up a helper class for doing this. You can see the code at github: https://github.com/quiqueqs/Toast-Expander/blob/master/src/com/thirtymatches/toasted/ToastedActivity.java
This is how you'd display a toast for 5 seconds (or 5000 milliseconds):
If you dig deeper in android code, you can find the lines that clearly indicate, that we cannot change the duration of Toast message.
and default values for duration are
Why eat Toast, when you can have the entire Snackbar: https://developer.android.com/reference/android/support/design/widget/Snackbar.html
Snackbar > Toast, Custom Toast, Crouton
A toast with custom background and view did the trick for me. I tested it in nexus 7 tablet and I noticed no fadein fadeout animation during looping. Heres the implementation:
Heres the custom textview used in above code:
@drawable/fragment_background is making my toast have rounded corner as in kitkat version. You can add other views too in the file. Any modifications for improvement and comments are encouraged as I am planning to implement this in my live app.
Toast duration can be hacked using a thread that runs the toast exclusively. This works (runs the toast for 10 secs, modify sleep and ctr to your liking):