Toast

http://developer.android.youdaxue.com/guide/topics/ui/notifiers/toasts.html#Positioning

创建自定义Toast View

To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView(View) method.
For example, you can create the layout for the toast visible in the screenshot to the right with the following XML (saved as layout/custom_toast.xml):


    
    

Notice that the ID of the LinearLayout element is "custom_toast_container". You must use this ID and the ID of the XML layout file "custom_toast" to inflate the layout, as shown here:

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
                (ViewGroup) findViewById(R.id.custom_toast_container));

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

你可能感兴趣的:(Toast)