在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用法,可以根據實際需求來選擇使用。