有没有办法创建自定义 toast 通知?
我想创建一条具有自定义背景和自定义圆形边框的 Toast 消息。但似乎我无法找到解决方案。
I want to create a Toast message with custom background and custom rounded border. But it seems I am not able to find the solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
此链接是一个起点 - 不确定可以自定义 toast 的哪些元素:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView
此链接(带有示例 XML)显示了如何更改 toast 背景和其他属性
而此链接显示了边距自定义的可能性(在代码中):
http: //developer.android.com/reference/android/widget/Toast.html#setMargin(float, float)
This link is a starting point - not sure about which elements of the toast can be customised:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView
This link (with the example XML) shows how you can change the toast background and other attributes
whereas this link shows the margin customisation possibilities (in code):
http://developer.android.com/reference/android/widget/Toast.html#setMargin(float, float)
下面是自定义Toast的代码:
Here is code to customize Toast:
Android中的自定义Toast可以轻松完成。
首先。使用您想要在 Toast 中使用的小部件创建您自己的 xml 布局,然后膨胀该布局。然后使用膨胀的布局查找视图对象并设置其内容,然后创建 Toast。因为代码会很长。我刚刚解释了我是如何做到的。
我在我的博客中对此进行了轻松解释: http://androiddesk.wordpress.com/2012/01/28/custom-notification-in-android-with-an-example/
希望这有帮助。
Custom Toast in android can be easily done.
First of all. Create your own xml layout with the widgets that you want in your Toast and then inflate the layout.Then use the inflated layout to find the view objects and the set its contents then create the Toast. As the code would be long. I've just explained how I've done it.
I've explained easily about this in my blog: http://androiddesk.wordpress.com/2012/01/28/custom-notification-in-android-with-an-example/
Hope this helped.
您可以在这里找到 http ://android-apps-blog.blogspot.com/2011/04/how-to-display-custom-toast-in-android.html 关于如何创建自定义 Toast 通知的好教程。
You can find here http://android-apps-blog.blogspot.com/2011/04/how-to-display-custom-toast-in-android.html a good tutorian on How to create a Custom Toast Notification.
如果您想要自定义 Toast,那么唯一最好的办法就是创建自定义对话框,或者您可以说自定义警报框,您可以使用对话框主题在应用程序中设计与 Toast 相同的设计。
要查看自定义框的教程,请参阅 YouTube 链接
http://www.youtube.com/watch?v=NBXMoMB9-k0
希望这对你有帮助..
If you want your custom toast than the only best thing is to create custom dialog or you can say custom alert box which you can design same as toast in your app by using themes of dialog box.
To see tutorial for custom box here is a youtube link
http://www.youtube.com/watch?v=NBXMoMB9-k0
Hope this will helpful to you..
我发现了两个我认为有用的例子......
昨天我只是在找它,因为我也对此感兴趣。
http://blog.webagesolutions.com/archives/161
helloandroid.com/tutorials/how-customize-toasts
无法发布多个链接 -.-
这就是为什么第二个是文本......
希望它有帮助:)
I found two I think useful examples...
Yesterday I just was looking for it, because I'm also interessted in it.
http://blog.webagesolutions.com/archives/161
helloandroid.com/tutorials/how-customize-toasts
Not able to post more than one link -.-
That's why the second one is as text...
Hope it helps :)