自定义 Android Toast 中的按钮? [英] Button in custom Android Toast?
问题描述
是否可以在 Toast 中添加按钮?
Is it possible to have a button in a Toast?
理论上,是的,因为您可以从 XML 布局构建自定义 Toast,但我尝试在其中放置一个按钮,但无法让它注册点击.有没有人设法做这样的事情?
In theory, yes because you can build a custom Toast from a layout in XML, but I tried to put a button in it and couldn't get it to register the click. Did anyone manage to do something like that?
推荐答案
无法单击 Toast.无法在 Toast 消息中捕获点击.您将需要为此构建一个对话框.查看创建对话框了解更多信息.
A toast can not be clicked. It is not possible to capture a click inside a toast message. You will need to build a dialog for that. Look at Creating Dialogs for more info.
Toast 类上的 API 声明 Toast 永远不会接收焦点,因为 toast 不是视图,所以没有 onClick 消息.我认为因此无法点击 Toast 的孩子.
The API on the Toast class state that a toast will never receive the focus and because a toast is not a view there is no onClick message. I would assume that therefore childs of a Toast can not be clicked as well.
这篇关于自定义 Android Toast 中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!