Thứ Năm, 27 tháng 11, 2014

Android Toast

http://javatechig.com/android/android-toast-example
Toast toast = Toast.makeText(getApplicationContext(), "Your toast message.",
                      Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
toast.show();
Custom Toast:
//get the LayoutInflater and inflate the custom_toast layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup)
findViewById(R.id.toast_layout_root));

//get the TextView from the custom_toast layout
TextView text = (TextView) layout.findViewById(R.id.toastText);
text.setText("This is my custom toast");

//create the toast object, set display duration,
//set the view as layout that's inflated above and then call show()
Toast t = new Toast(getApplicationContext());
t.setDuration(Toast.LENGTH_LONG);
t.setView(layout);
t.show();

Không có nhận xét nào:

Đăng nhận xét