Android:同时 toast 2 次

标签 android toast

好的,我有 1 个自定义 toast(xml 布局)并且效果很好:

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout));
    ImageView image = (ImageView) layout.findViewById(R.id.logo);        
    image.setImageResource(R.drawable.logo);
    title = (TextView) layout.findViewById(R.id.title);        
    txt = (TextView) layout.findViewById(R.id.text);
    toast = new Toast(appContext);
    toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.BOTTOM, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);        

但是当我尝试以同样的方式制作第二个时,我收到错误“未找到来源”,这并没有真正告诉我任何错误。

    LayoutInflater infl = getLayoutInflater();
    View lay = infl.inflate(R.layout.toast_arrows, (ViewGroup) findViewById(R.id.toast_lay));                        
    toastarrows = new Toast(appContext);
    toastarrows.setGravity(Gravity.FILL_HORIZONTAL|Gravity.CENTER, 0, 0);
    toastarrows.setDuration(Toast.LENGTH_SHORT);
    toastarrows.setView(lay);                
    toastarrows.show();

我希望这 2 个 toast 几乎同时出现在屏幕的不同位置。 谁能告诉我这段代码有什么问题?

最佳答案

你确定可以同时显示2个Toast吗? 我对此不确定,我试过了,但我只能显示一个 toast 。 你试过只显示第二个吗?

关于Android:同时 toast 2 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4012949/

相关文章:

Android 媒体播放器错误 (-38, 0) "stop called in state 0"

Android SDK 管理器 - 要下载什么 API?

android - 更改 fragment 中的操作栏菜单

android - 尝试在 Cocos2d-X C++ 中设置一个带有整数的 CCLabelTTF 作为其字符串的一部分

javascript - java.lang.RuntimeException : Can't toast on a thread that has not called Looper. 准备()

NDK android studio 中的 java.lang.UnsatisfiedLinkError

java - SurfaceView 中的 Toast

android - 不显示 toast 消息 android

ios - 当您的应用程序打开并位于前台时显示一个 iOS 通知横幅?

android - 如何在启动 Asynctask 10 秒后显示 toast