2 ways to implement a Toast

Quickly share your Android Code Snippets here...

2 ways to implement a Toast

Postby ninor » Thu Oct 16, 2008 5:45 am

2 ways to implement a Toast

Very simple Toast Image example:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Toast toast = new Toast(this);
  2.  
  3. ImageView view = new ImageView(this);
  4.  
  5. view.setImageResource(R.drawable.icon);
  6.  
  7. toast.setView(view);
  8.  
  9. toast.show();
  10.  
  11.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Another one:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG);
  3.  
  4. View textView = toast.getView();
  5.  
  6. LinearLayout lay = new LinearLayout(this);
  7.  
  8. lay.setOrientation(LinearLayout.HORIZONTAL);
  9.  
  10. ImageView view = new ImageView(this);
  11.  
  12. view.setImageResource(R.drawable.icon);
  13.  
  14. lay.addView(view);
  15.  
  16. lay.addView(textView);
  17.  
  18. toast.setView(lay);
  19.  
  20. toast.show();
  21.  
  22.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


The image is not on the background the text is on, but to achieve that, you'll need to extend the Toast class.

SDK Version compatible: 0.9, 1.0

Thanks to MrSnowFlake for creating and sharing this snippet!
Original Post
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 5 guests