在Android中,Toast用于显示短暂的消息提示。下面是一些Toast的用法:
Toast.makeText(context, "Hello World!", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "Hello World!", Toast.LENGTH_LONG).show();
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_container));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
Toast toast = Toast.makeText(context, "Hello World!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
toast.show();
这些是一些常见的Toast用法,可以根据实际需求来选择使用。