如何确定android中是否显示任何toast

如何确定android中是否显示任何toast,android,android-espresso,android-toast,Android,Android Espresso,Android Toast,有没有办法检查android中是否显示了toast消息? 我正在编写一个idlingResource,我希望在将资源返回为空闲之前,确保当前没有显示toast 创建自定义吐司 在方法中添加此代码 custom_toast.xml 谢谢你的回答,但在我的情况下,我需要能够检测系统范围内的祝酒词,即即使是其他应用程序也会产生祝酒词。你有其他应用程序产生的祝酒词的id吗?你是否检查LieForBananas在你问题下方的评论?我想这对你有帮助。退房 private Toast myToast = nu

有没有办法检查android中是否显示了toast消息? 我正在编写一个idlingResource,我希望在将资源返回为空闲之前,确保当前没有显示toast

创建自定义吐司

在方法中添加此代码

custom_toast.xml


谢谢你的回答,但在我的情况下,我需要能够检测系统范围内的祝酒词,即即使是其他应用程序也会产生祝酒词。你有其他应用程序产生的祝酒词的id吗?你是否检查LieForBananas在你问题下方的评论?我想这对你有帮助。退房
private Toast myToast = nuul; // Create class Level Object to
String message = "Your Message";
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
     the                    (ViewGroup) findViewById(R.id.custom_toast_container));

TextView text = (TextView) layout.findViewById(R.id.custom_toast_text);
text.setText(Message);

myToast = new Toast(getApplicationContext());
myToast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
myToast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
myToast.setDuration(Toast.LENGTH_LONG);
myToast.setView(layout);
myToast.show();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_toast_container"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="8dp"
    android:background="#80000000">

    <TextView
        android:id="@+id/custom_toast_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:enabled="true"
        android:textSize="16dp"
        />
</LinearLayout>
 if (myToast != null) 
  myToast.cancel(); // Dismiss the toast