您的位置:首页 > 移动开发 > Android开发

android - Toasts

2015-12-12 16:52 363 查看
A toast provides simple feedback about an operation in a small popup.

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();

Note: Do not use the public constructor for a Toast unless you are going to define the layout
with
setView(View)
.
If you do not have a custom layout to use, you must use
makeText(Context,
int, int)
to create the Toast.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: