Android: Toast notifications
This isn't a question, more of a "here-ya-go".
Was doing some snooping tonight on the commits on Gihub, and Toast notification do, in fact, exist for Android, and DO WORK.
var toast = Titanium.UI.createNotification({
duration: 2000,
message: "Hi, I'm a toast!"
});
toast.show();
toast.cancel() also closes the current active toast. I've noticed that the duration isn't dependable, but I've more testing to do.
Enjoy!
Andrew
2 Answers
-
Duration can be set either to Ti.UI.NOTIFICATION_DURATION_LONG or NOTIFICATION_DURATION_SHORT values.
And, if you want longer durations you can use setTimeout and repeatedly call .show() on the toast notification object.
-
Thanks for finding this.
They're still woefully undocumented by all accounts.
I can't find any mention, beyond the cited duration constants, in the docs.Digging around in the source code, specifically here:
titanium_mobile/android/modules/ui/src/ti/modules/titanium/ui/widget/TiUINotification.java
Reveals a number of properties in addition to
duration
.These would be:
- horizontalMargin - verticalMargin - offsetX - offsetY - gravity