从Toast对象获取Toast消息

时间:2015-03-20 05:50:06

标签: android testing toast

有没有办法在Android中获取与特定Android Toast对象关联的消息?

toast=Toast.makeText(getAppContext(), message, Toast.LENGTH_LONG);
toast.show();

现在在我的测试类中,我想从这个toast对象中获取消息

1 个答案:

答案 0 :(得分:4)

  

有没有办法让消息与特定的android相关联   android中的Toast对象?

这样做:

Toast toast=Toast.makeText(getAppContext(), message, Toast.LENGTH_LONG);
toast.show();
View view = toast.getView(); 
TextView tv = (TextView)view.findViewById(android.R.id.message);
String strMessage=tv.getText().toString();
相关问题