Customized Toasts

I love Android Toasts :)

Let me show you a way to construct Toast with customized content:

Toast customizedToast = Toast.makeText(this, "Customized toast test, Toast.LENGTH_LONG);
customizedToast.setGravity(Gravity.TOP, 0, 0);
LinearLayout mLayout = new LinearLayout(this);
mLayout.setOrientation(LinearLayout.VERTICAL);
TextView mTextView = new TextView(this);
mTextView.setText("Title here");
ImageView mImageView = new ImageView(this);
mImageView.setImageDrawable(-a drawable here-);
mLayout.addView(mTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
mLayout.addView(mImageView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
customizedToast.setView(mLayout);
customizedToast.show();
FacebookGoogle BookmarksTwitterFriendFeedGoogle GmailBlogger PostGoogle ReaderHotmailWordPressShare

Related posts:

  1. Guice for Android, dependency injection made easy with roboguice!
  2. Styled text in TextView
  3. Android custom dialog with no title
  4. TabHost with tabs at the bottom
  5. Simple AlertDialog tutorial
Leave a Comment