Different effects of toast in Android 5

Source: Internet
Author: User

First, the results of the operation

Second, the main code

Package Com.otn.android.toast;import Java.util.timer;import Java.util.timertask;import android.app.Activity;import Android.app.alertdialog;import Android.os.bundle;import Android.view.gravity;import Android.view.LayoutInflater; Import Android.view.view;import Android.view.viewgroup;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.textview;import Android.widget.toast;public class Mytoast extends Activity implements Onclicklistener {  private static final String toastbtn_1 = "This is the default toast display";p rivate static final String toastbtn_2 = "This is a toast display for a custom location";p rivate Static final String toastbtn_3 = "This is a toast display with pictures";p rivate static final String toastbtn_4 = "This is a fully customized toast display";p rivate Stati C final String toastbtn_5 = "This is a long toast display";p rivate button toastbtn_1, toastbtn_2, Toastbtn_3, Toastbtn_4, Toastbtn_5;pri vate toast toast = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stubsuper.oncreate (savedinstancestate); Setcontentview (r.layout.main); toastBtn_1 = (Button) Findviewbyid (r.id.button_1); toastbtn_2 = (Button) Findviewbyid (r.id.button_2); toastbtn_3 = (Button) Findviewbyid ( R.id.button_3); toastbtn_4 = (Button) Findviewbyid (r.id.button_4); toastbtn_5 = (Button) Findviewbyid (r.id.button_5); Toastbtn_1.setonclicklistener (This), Toastbtn_2.setonclicklistener (This), Toastbtn_3.setonclicklistener (this); Toastbtn_4.setonclicklistener (this); Toastbtn_5.setonclicklistener (this);} @Overridepublic void OnClick (View v) {Alertdialog.builder Builder; Alertdialog Dialog;switch (V.getid ()) {Case R.id.button_1:toast.maketext (Getapplicationcontext (), TOASTBTN_1, Toast.length_long). Show (); Break;case r.id.button_2:toast = Toast.maketext (Getapplicationcontext (), TOASTBTN_2, Toast.length_long); toast.setgravity (gravity.center, 0, 0); Toast.show (); Break;case r.id.button_3:toast = Toast.maketext (Getapplicationcontext (), toastbtn_3,toast.length_long); toast.setgravity(Gravity.center, 50,-100); LinearLayout layout = (linearlayout) toast.getview () ImageView image = New ImageView (Getapplicationcontext ()); Image.setimageresource (R.drawable.wallpaper_tree_small); Layout.addview (image, 0); Toast.show (); break;case R.id.button_4:layoutinflater inflater = Getlayoutinflater (); View view = Inflater.inflate (R.layout.userdefinedtoast, (ViewGroup) Findviewbyid (r.id.toast_layout)); TextView Txtview_title = (TextView) View.findviewbyid (r.id.txt_title); TextView Txtview_context = (TextView) View.findviewbyid (r.id.txt_context); ImageView ImageView = (ImageView) View.findviewbyid (r.id.image_toast); toast = new Toast (Getapplicationcontext ()); Toast.setgravity (gravity.center, 0, 0); toast.setduration (Toast.length_long); Toast.setview (view); Toast.show (); Break;case r.id.button_5: Layoutinflater inflater1 = Getlayoutinflater (); View view1 = Inflater1.inflate (R.layout.userdefinedtoast, (ViewGroup) Findviewbyid (r.id.toast_layout)); TextView txtview_title1 = (TextView) View1.findviewbyid (R.Id.txt_title); TextView txtview_context1 = (TextView) View1.findviewbyid (r.id.txt_context); ImageView imageView1 = (ImageView) View1.findviewbyid (r.id.image_toast); builder = new Alertdialog.builder (this); Builder.setview (view1);d ialog = Builder.create ();d ialog.show (); Toast.maketext (this, toastbtn_5, Toast.length_long). Show (); break;default:break;}}}

Different effects of toast in Android 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.