我可以访问在运行时创建的Android Toast XML吗?

问题描述 投票:0回答:2

我需要访问已创建的Toast XML代码,该代码已在运行时显示以用于测试。有什么办法吗?

android testing toast
2个回答
0
投票

也许您应该以编程方式使用Toast消息,就像Java中这样:

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();

在科特林:

val text = "Hello toast!"
val duration = Toast.LENGTH_SHORT

val toast = Toast.makeText(applicationContext, text, duration)
toast.show()

我认为您可以像测试函数一样使用它。

此外,如果您想进一步了解Toast消息,请访问Android开发者博客的链接:https://developer.android.com/guide/topics/ui/notifiers/toasts#kotlin


0
投票
Toast toast = Toast.makeText(getApplicationContext(),  "Hello toast!", Toast.LENGTH_SHORT);
toast.show();
View toastView = toast.getView();
© www.soinside.com 2019 - 2024. All rights reserved.