"Go" notification toast verbose usage (show view)

Source: Internet
Author: User

Original URL: http://www.pocketdigi.com/20100904/87.html

Learn about the use of Android notification toast today, toast displays a message to the user on the phone screen, and the information will automatically disappear after a period of time. The information can be simple text or complex pictures and other content (display a view).
See:

There are two uses for today's demo, such as
Main.xml:

  1. <? XML version="1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="Fill_parent"
  5. android:layout_height="Fill_parent"
  6. >
  7. <button Android:id="@+id/button1"
  8. Android:layout_width="Fill_parent"
  9. Android:layout_height="Wrap_content"
  10. Android:text="toast Show view"
  11. />
  12. <button Android:id="@+id/button2"
  13. Android:layout_width="Fill_parent"
  14. Android:layout_height="Wrap_content"
  15. Android:text="Toast Direct output"
  16. />
  17. </LinearLayout>

Two buttons, very simple
Program code:

  1. Package com. Pocketdgig. Toast;
  2. Import android. App. Activity;
  3. Import android. Content. Context;
  4. Import android. Os. Bundle;
  5. Import android. View. Layoutinflater;
  6. Import android. View. View;
  7. Import android. View. View. Onclicklistener;
  8. Import android. Widget. Button;
  9. Import android. Widget. TextView;
  10. Import android. Widget. Toast;
  11. Public Class main extends Activity {
  12. /** Called when the activity is first created. * /
  13. @Override
  14. public void onCreate(Bundle savedinstancestate) {
  15. Super. OnCreate(savedinstancestate);
  16. Setcontentview(R. Layout. Main);
  17. button button1= (button)Findviewbyid(R. ID. Button1);
  18. Button1. Setonclicklistener(bt1lis);
  19. button button2= (button)Findviewbyid(R. ID. Button2);
  20. Button2. Setonclicklistener(bt2lis);
  21. }
  22. onclicklistener Bt1lis=new Onclicklistener() {
  23. @Override
  24. Public void onClick(View v) {
  25. Showtoast();
  26. }
  27. };
  28. onclicklistener Bt2lis=new Onclicklistener() {
  29. @Override
  30. Public void onClick(View v) {
  31. Toast. Maketext(main. This,"Direct output test", Toast. Length_long). show();
  32. }
  33. };
  34. public void showtoast() {
  35. Layoutinflater li= (layoutinflater)getsystemservice(Context. Layout_inflater_service);
  36. View View=li. Inflate(R. Layout. Toast,null);
  37. //Convert layout file Toast.xml to a view
  38. Toast Toast=new toast(this);
  39. Toast. Setview(view);
  40. //Load view, which displays the contents of Toast.xml
  41. TextView TV= (TextView)view. Findviewbyid(R. ID. TV1);
  42. TV. SetText("Toast display view content");
  43. //modify content in TextView
  44. Toast. Setduration(Toast. Length_short);
  45. //Set display time, long time Toast.length_long, short time for Toast.length_short, can not edit yourself
  46. Toast. Show();
  47. }
  48. }

Here's what's toast.xml:

  1. <? XML version="1.0" encoding="Utf-8"?>
  2. <linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="Fill_parent"
  5. android:layout_height="Fill_parent"
  6. >
  7. <imageview android:src="@drawable/toast"
  8. Android:layout_width="Wrap_content"
  9. Android:layout_height="Wrap_content"
  10. />
  11. <textview Android:id="@+id/tv1"
  12. Android:text=""
  13. Android:layout_width="Wrap_content"
  14. Android:layout_height="Wrap_content"
  15. />
  16. </LinearLayout>

Source code Download: [Download id= "4″]

©, frozen fish. Please respect the author's labor results, copy reproduced and retain the site link! Application Development Notes

"Go" notification toast verbose usage (show view)

Related Article

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.