Related Topics

What is Mobile Computing in Hindi?

Brief history of mobile technology in Hindi

Mobile Phone Generations in Hindi

The Mobile Ecosystem in Hindi

Types of Mobile Applications in Hindi

Mobile Information Architecture in Hindi

Android Versions in Hindi

Features of Android in Hindi

Android Architecture in Hindi

Installing Android SDK Tools in Hindi

Configuring Android in Eclipse IDE in Hindi

Android Development Tools (ADT) in Hindi

Creating Android Virtual Devices (AVD) in Hindi

Creating First Android Application in Hindi

Anatomy of Android Application in Hindi

Deploying Android App on USB Connected Android Device in Hindi

Android Application Components in Hindi

Android Activity Life Cycle in Hindi

Android Activities in Hindi

Exploring Intent Objects in Hindi

Linking Activities Using Intents in Hindi

Android Fragment Lifecycle in Hindi

Android UI Layouts in Hindi

Adapting to Display Orientation in Android in Hindi

Action Bar in Android in Hindi

Android Alarm Manager in Hindi

Displaying Analog & Digital Clocks in Android in Hindi

Event Handling in Android in Hindi

Android Menus in Hindi

Data Storage Options in Android in Hindi

External Storage in Android in Hindi

Content Providers in Android in Hindi

Views in Android in Hindi

Button in Android in Hindi

ToggleButton in Android in Hindi

CheckBox in Android in Hindi

RadioButton in Android in Hindi

Spinner in Android in Hindi

WebView in Android in Hindi

EditText in Android in Hindi

DatePicker in Android in Hindi

TimePicker in Android in Hindi

ListView in Android in Hindi

ProgressBar in Android in Hindi

Handling UI Events in Android in Hindi

ListFragment in Android in Hindi

DialogFragment in Android in Hindi

Context in Android in Hindi

Popup in Android in Hindi

ImageView in Android in Hindi

ImageSwitcher in Android in Hindi

AlertDialog in Android in Hindi

AlarmManager in Android in Hindi

SMS in Android in Hindi

E-mail in Android in Hindi

MediaPlayer in Android in Hindi

Using Camera in Android in Hindi

Video Recording in Android in Hindi

Telephony Manager in Android in Hindi

Android SQLite Database in Hindi

SQLite database operations in Hindi

Publishing Android Applications in Hindi

Deploying APK Files in Android in Hindi

Related Subjects

Toast in Android in Hindi

RGPV University / DIPLOMA_CSE / MOBILE COMPUTING

Toast in Android - Use of Toast in Android - Creating a Simple Toast Message in Android - Syntax of Toast in Android

Toast in Android - एक परिचय

Android में Toast एक साधारण, छोटा संदेश होता है जो यूज़र को कुछ जानकारी देता है। यह स्क्रीन पर थोड़े समय के लिए दिखाई देता है और फिर अपने आप गायब हो जाता है। इसका उपयोग आमतौर पर किसी कार्य के सफल होने या विफल होने की जानकारी देने के लिए किया जाता है, जैसे कि "सफलता से सेव किया गया" या "नेटवर्क कनेक्शन नहीं है"। यह यूज़र इंटरफेस में किसी भी तरह से हस्तक्षेप नहीं करता है, क्योंकि यह स्क्रीन के निचले हिस्से में छोटा सा दिखाई देता है।

Use of Toast in Android - Android में Toast का उपयोग

  • Android में Toast का मुख्य उद्देश्य एक सूचनात्मक संदेश दिखाना है, जो यूज़र को किसी क्रिया या घटना की जानकारी प्रदान करता है।
  • यह संदेश यूज़र को परेशान किए बिना स्क्रीन पर कुछ सेकंड के लिए दिखाई देता है और फिर खुद-ब-खुद गायब हो जाता है।
  • Toast का उपयोग आमतौर पर जानकारी देने, पुष्टि करने, या किसी कार्य के सफल या असफल होने की जानकारी देने के लिए किया जाता है।
  • यह ऐप के UI को बाधित नहीं करता है, क्योंकि यह एक छोटा, बिना किसी इंटरएक्शन के संदेश होता है।

Creating a Simple Toast Message in Android - Android में सरल Toast संदेश बनाना

Toast संदेश बनाने के लिए सबसे पहले हमें `Toast` क्लास का उपयोग करना होता है। एक साधारण Toast संदेश को बनाने के लिए निम्नलिखित स्टेप्स का पालन करें:

  • सबसे पहले, हमें `Toast` क्लास को इंपोर्ट करना होगा।
  • फिर, हमें `Toast.makeText()` मेथड का उपयोग करना होता है, जिसमें तीन पैरामीटर होते हैं:
    • Context: जिस एक्टिविटी या एप्लिकेशन से आप संदेश दिखाना चाहते हैं।
    • Text: वह संदेश जो यूज़र को दिखाना है।
    • Duration: संदेश दिखाने की अवधि (जैसे Toast.LENGTH_SHORT या Toast.LENGTH_LONG)।
  • इसके बाद, हमें `show()` मेथड का उपयोग करके इसे स्क्रीन पर दिखाना होता है।

यहां एक साधारण Toast संदेश का उदाहरण दिया गया है:

Toast.makeText(getApplicationContext(), "यह एक साधारण Toast संदेश है", Toast.LENGTH_SHORT).show();

Syntax of Toast in Android - Android में Toast का सिंटैक्स

  • Toast संदेश बनाने के लिए मुख्य सिंटैक्स इस प्रकार होता है:
  • Toast.makeText(context, text, duration).show();
    • context: यहाँ पर आपको एक्टिविटी का संदर्भ देना होता है।
    • text: यह वह संदेश है जो आप यूज़र को दिखाना चाहते हैं।
    • duration: यह वह समय है जिसके लिए संदेश स्क्रीन पर दिखाई देगा। इसे Toast.LENGTH_SHORT या Toast.LENGTH_LONG के रूप में सेट किया जा सकता है।

Toast के प्रकार - Types of Toast in Android

  • Toast.LENGTH_SHORT: यह Toast संदेश को 2 सेकंड के लिए स्क्रीन पर दिखाता है।
  • Toast.LENGTH_LONG: यह Toast संदेश को 3.5 सेकंड के लिए स्क्रीन पर दिखाता है।

Toast को कस्टमाइज करना - Customizing Toast in Android

आप Android में Toast को कस्टमाइज भी कर सकते हैं, जैसे कि उसका बैकग्राउंड रंग बदलना, टेक्स्ट का रंग बदलना, या उसे एक कस्टम लेआउट के साथ दिखाना।

  • आप `Toast.setView()` का उपयोग करके अपने कस्टम लेआउट को सेट कर सकते हैं।
  • आप `Toast.setGravity()` का उपयोग करके Toast की स्थिति को बदल सकते हैं। उदाहरण के लिए, इसे स्क्रीन के बीच में दिखाने के लिए आप इसे कस्टम ग्रैविटी सेट कर सकते हैं।

Toast की स्थिति बदलना - Changing Toast Position in Android

आप Toast की स्थिति को सेट कर सकते हैं, जैसे कि उसे स्क्रीन के बीच में, ऊपर या नीचे दिखाना। इसके लिए `Toast.setGravity()` का उपयोग किया जाता है।

Toast toast = Toast.makeText(getApplicationContext(), "यह कस्टम Toast है", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); // इसे स्क्रीन के मध्य में दिखाने के लिए toast.show();

Toast के साथ इमेज का उपयोग - Using Image with Toast in Android

आप Toast के साथ एक इमेज भी जोड़ सकते हैं। इसके लिए आपको `Toast.setView()` का उपयोग करना होता है, जिसमें आप एक कस्टम लेआउट सेट करते हैं।

LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, null); ImageView image = layout.findViewById(R.id.toast_image); image.setImageResource(R.drawable.toast_image); Toast toast = new Toast(getApplicationContext()); toast.setView(layout); toast.setDuration(Toast.LENGTH_SHORT); toast.show();

FAQs

Toast in Android is a small, simple message displayed on the screen for a short time. It is used to show information to the user without interrupting the UI. For example, it can be used to show messages like "Data saved successfully" or "Network error." It disappears automatically after a few seconds.

To create a Toast message in Android, use the `Toast.makeText()` method. You need to provide three parameters: Context (the current activity), the text to display, and the duration (either Toast.LENGTH_SHORT or Toast.LENGTH_LONG). Finally, use `show()` to display the message.

Toast.makeText(getApplicationContext(), "This is a Toast message", Toast.LENGTH_SHORT).show();

There are two main types of Toast in Android: Toast.LENGTH_SHORT and Toast.LENGTH_LONG.
Toast.LENGTH_SHORT displays the message for 2 seconds, while Toast.LENGTH_LONG displays it for 3.5 seconds.

You can customize Toast in Android by using a custom layout. You can use a custom view for the Toast message and change its background color, text color, or even add an image. To customize, use the `Toast.setView()` method.

You can change the position of a Toast message using the `Toast.setGravity()` method. This allows you to set the position of the Toast on the screen, such as center, top, or bottom.

Toast toast = Toast.makeText(getApplicationContext(), "Custom Toast", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show();

Yes, you can add images to Toast messages in Android. To do this, you need to use a custom layout for the Toast, which includes an ImageView for the image and a TextView for the text. You can then set this custom view using `Toast.setView()`.

LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom_toast, null); ImageView image = layout.findViewById(R.id.toast_image); image.setImageResource(R.drawable.toast_image); Toast toast = new Toast(getApplicationContext()); toast.setView(layout); toast.setDuration(Toast.LENGTH_SHORT); toast.show();
Toast setView setGravity

Please Give Us Feedback