Change Old Toast Message With Message Bar

Message Bar Library is Best Replacement For Old Toast message in android. you have seen Square Toast message in Gmail application when you Delete Mail from the list. That kind of Toast Message you can display.
You want decent or same look of Toast message in all android versions because Google Developer Change GUI component in each and every version. so your app look will change in all different version of Android Operating System. This is very simple and customize-able Toast message. you can customize its layout as per your application layout. To add this library download It from here. If you don't know how to add library in project you can check out my tutorial Add Action bar in Any Android Application And Apply same method for Add this library in your project.

To Display Message you have to call Show() method of Message Bar Library.here i have Written tutorial for you so you can easily add these in your application.
MessageBarDemo.java  

package com.example.samplecollection;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import net.simonvt.messagebar.*;

public class MessageBarDemo extends Activity {

 Button bt1, bt2;
 MessageBar mb;
 private int mCount;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.message_bar_demo);
  bt1 = (Button) findViewById(R.id.button1);
  bt2 = (Button) findViewById(R.id.button2);

  mb = new MessageBar(this);

  bt1.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    mb.show("Simple Message Bar...");
   }
  });
  bt2.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    Bundle b = new Bundle();
                b.putInt("count", mCount);
                mb.show("Message " + mCount, "Button!", android.R.drawable.ic_menu_revert, b);
                mCount++;
   }
  });
 }
}

Note - One More Thing you have to do is add following style in your project\ values\ styles.xml file.
 <item name="messageBarContainerStyle">@style/MessageBar.Container</item>        <item name="messageBarTextStyle">@style/MessageBar.Message</item>        <item name="messageBarButtonStyle">@style/MessageBar.Button</item>
Screen Shots


These Library is developed by Simon Vig Therkildsen. and all credit goes to him. and if any thing occur or if you have any question regarding library you can ask here. For More Advance Libraries and Tutorials Subscribe to our blog.

Keep Coding..

0 comments :

Post a Comment