我需要访问已创建的Toast XML代码,该代码已在运行时显示以用于测试。有什么办法吗?
也许您应该以编程方式使用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
Toast toast = Toast.makeText(getApplicationContext(), "Hello toast!", Toast.LENGTH_SHORT);
toast.show();
View toastView = toast.getView();