Android toasts

Android toasts 


  • Introduction to android toasts in Hindi
  • Methods used with android toasts in Hindi 
  • Creating android toasts in Hindi 
  • Example


Introduction to android toasts 


Android toast एक simple popup मैसेज होता है जो कुछ देर के लिए स्क्रीन पर appear होता है और automatically disappear हो जाता है। उदाहरण के लिए जब आप अपने device से कोई मैसेज भेजते है, तो आपको एक toast शो होता है, जिसमे लिखा होता है "Message sent " और वो कुछ देर बाद automatically disappear हो जाता है।

Android toasts की size उतनी ही होती है, जितना बड़ा आपका मैसेज होता है। Current activity visible होती है, आप इसके साथ interact कर सकते है।



Methods used with android toasts


makeText() -  ये method एक toast create करने के काम में आता है. इस मेथड को आप Toast क्लास के object पर कॉल करते है। इस method में आप current application का context, आपका text message और toast की duration पास करते है। 

structure   -   public static Toast makeText(context-of-Application, text-Message, duration-of-Message);


Example -  Toast.makeText(getApplicationContext(), "Welcome to besthinditutorials.com", Toast.LENGTH_SHORT); 


show() -  ये मेथड toast को display करता है। इस मेथड को आप Toast क्लास के object पर call करते है। 

structure  -  public void show() ;

Example  -   toastObject.show();


setGravitiy() - इस मेथड से आप अपने toast मैसेज को अपनी application में मन चाही position पर सेट कर सकते है।

structure  -  public void setGravity(int, int, int);

Example -  toastObject.setGravity(200, 50, 200);        


Creating android toasts     


  1. Android में toasts क्रिएट करने के लिए सबसे पहले Toast क्लास का ऑब्जेक्ट क्रिएट करिये।
  2. इसके बाद Toast क्लास के object पर makeText() मेथड कॉल कीजिये और उसमे current application का context, text message और duration पास कीजिये।     
  3. इसके बाद toast object पर setGravitiy() मेथड कॉल करके toast मैसेज की position को सेट कीजिये।
  4. इसके बाद toast को शो करने के लिए  toast object पर show() मेथड कॉल कीजिये।      


Example 


Context appContext = getApplicationContext();
CharSequence msg = "Welcome to besthinditutorials.com";
int duration = Toast.LENGTH.SHORT;

Toast mytoast = Toast.makeText(appContext, msg, duration);
toast.setGravity(200,50,200);
toast.show();

Comments

Add2

Popular posts from this blog

Android menus

Android broadcast receivers