两种实现Toast 的例子(图片&文字)

xiaoxiao2022-06-12  28

Toast主要用来提示用户,以实现友好的用户体验,这里给出两个Toast的例子:1、使用图片

Toast toast = new Toast(this); ImageView view = new ImageView(this); view.setImageResource(R.drawable.icon); toast.setView(view); toast.show(); 复制代码

2、使用文字对话框

Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG); View textView = toast.getView(); LinearLayout lay = new LinearLayout(this); lay.setOrientation(LinearLayout.HORIZONTAL); ImageView view = new ImageView(this); view.setImageResource(R.drawable.icon); lay.addView(view); lay.addView(textView); toast.setView(lay); toast.show(); 复制代码 相关资源:Java 面经手册·小傅哥(公众号:bugstack虫洞栈).pdf
转载请注明原文地址: https://www.6miu.com/read-4933919.html

最新回复(0)