Android Tips Toast

Source: Internet
Author: User

Steps:

To set the listener event step
1. Event source, such as key btn_simple
2. Event OnClick
3. Listener New Onclicklistener
3. Bind event Source with Event Setonclicklistener (new Onclicklistener () {}

Layout:

 <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:l ayout_height= "Match_parent" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@di Men/activity_horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingTop= "@dimen/activity_vertical_margin" android:orientation= "vertical" tools:context= ". Mainactivity "> <button android:id=" @+id/btn_simple "android:layout_width=" wrap_content "Android:layout_height=" Wrap_content "android:text=" General toast "/> <button androi            D:id= "@+id/btn_toast" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:text= "with picture toast"/> </linearlayout> 

 activity:

 public class Mainactivity extends Activity {private Button btn_simple;        Private Button Btn_toast;            @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);            Setcontentview (R.layout.activity_main);            Btn_simple = (Button) Findviewbyid (r.id.btn_simple);            Btn_toast = (Button) Findviewbyid (r.id.btn_toast); Btn_simple.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v)                {Toast.maketext (Mainactivity.this, "Simple text message", Toast.length_short). Show ();            }            }); /* * Toast with pictures */Btn_toast.setonclicklistener (new Onclicklistener () {@ Override public void OnClick (View v) {//create toast toast toast = new to                    AST (Mainactivity.this);              Set Toast Display Location      Toast.setgravity (gravity.center, 0, 0);                    Create a ImageView ImageView IV = new ImageView (mainactivity.this);                    Iv.setimageresource (R.drawable.tools);                    Create container LinearLayout ll = new LinearLayout (mainactivity.this);                    Ll.addview (iv);                    Create a text TextView TV = new TextView (mainactivity.this);                    Tv.settext ("With picture hint information");                    Tv.settextsize (24);                    Tv.settextcolor (Color.magenta);                    Ll.addview (TV);                    Toast.setview (LL);                    Toast.setduration (Toast.length_short);                Toast.show ();        }            }); }    }

Tips for Android toast

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.