got*_*ube 7 android toast android-toast
我希望一个Toast消息显示在一个位置,另一个Toast消息同时显示在另一个位置.
多个Toast消息似乎总是按顺序排队和显示.是否可以同时显示两条消息?
是否有一种解决方法,至少提供该外观,并不涉及搞乱活动布局?
编辑:似乎第一个问题的答案是否定的,这是不可能的.解决方法怎么样?对我来说,一个解决方案包括像Toast一样出现在应用程序之上的东西,并且不会干扰用户与应用程序的交互(因此,不是AlertDialogue或任何调用onPause()等的东西).
正如S͢kyD͢ream所说,它无法完成.但IS的解决方法!您可以创建Toast可包含任何内容的自定义View.这意味着您可以在一个吐司内的不同位置放置两条消息.
你可以在这里找到如何做到这一点,或者你可以直接从这个片段开始:
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7060 次 |
| 最近记录: |