1- page.title=Toast Notifications
2- parent.title=Notifications
3- parent.link=index.html
1+ page.title=Toasts
42@jd:body
53
64<div id="qv-wrapper">
7- <div id="qv">
8- <h2>Quickview</h2>
9- <ol>
10- <li>A toast is a message that appears on the surface of the screen for a moment, but it
11- does not take focus (or pause the current activity), so it cannot accept user input</li>
12- <li>You can customize the toast layout to include images</li>
13- </ol>
14-
5+ <div id="qv">
156 <h2>In this document</h2>
167 <ol>
178 <li><a href="#Basics">The Basics</a></li>
@@ -26,22 +17,17 @@ does not take focus (or pause the current activity), so it cannot accept user in
2617 </div>
2718</div>
2819
29- <p>A toast notification is a message that pops up on the surface of the window.
30- It only fills the amount of space required for the message and the user's current
31- activity remains visible and interactive. The notification automatically fades in and
32- out, and does not accept interaction events.</p>
20+ <p>A toast provides simple feedback about an operation in a small popup.
21+ It only fills the amount of space required for the message and the current
22+ activity remains visible and interactive.
23+ For example, navigating away from an email before you send it triggers a
24+ "Draft saved" toast to let you know that you can continue editing later.
25+ Toasts automatically disappear after a timeout.</p>
3326
34- <p>The screenshot below shows an example toast notification from the Alarm application.
35- Once an alarm is turned on, a toast is displayed to assure you that the
36- alarm was set.</p>
3727<img src="{@docRoot}images/toast.png" alt="" />
3828
39- <p>A toast can be created and displayed from an {@link android.app.Activity} or
40- {@link android.app.Service}. If you create a toast notification from a Service, it
41- appears in front of the Activity currently in focus.</p>
42-
43- <p>If user response to the notification is required, consider using a
44- <a href="notifications.html">Status Bar Notification</a>.</p>
29+ <p>If user response to a status message is required, consider instead using a
30+ <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Notification</a>.</p>
4531
4632
4733<h2 id="Basics">The Basics</h2>
@@ -90,8 +76,6 @@ To nudge it down, increase the value of the last parameter.
9076
9177<h2 id="CustomToastView">Creating a Custom Toast View</h2>
9278
93- <img src="{@docRoot}images/custom_toast.png" alt="" style="float:right" />
94-
9579<p>If a simple text message isn't enough, you can create a customized layout for your
9680toast notification. To create a custom layout, define a View layout,
9781in XML or in your application code, and pass the root {@link android.view.View} object
@@ -105,17 +89,17 @@ with the following XML (saved as <em>toast_layout.xml</em>):</p>
10589 android:orientation="horizontal"
10690 android:layout_width="fill_parent"
10791 android:layout_height="fill_parent"
108- android:padding="10dp "
92+ android:padding="8dp "
10993 android:background="#DAAA"
11094 >
111- <ImageView android:id ="@+id/image "
95+ <ImageView android:src ="@drawable/droid "
11296 android:layout_width="wrap_content"
113- android:layout_height="fill_parent "
114- android:layout_marginRight="10dp "
97+ android:layout_height="wrap_content "
98+ android:layout_marginRight="8dp "
11599 />
116100 <TextView android:id="@+id/text"
117101 android:layout_width="wrap_content"
118- android:layout_height="fill_parent "
102+ android:layout_height="wrap_content "
119103 android:textColor="#FFF"
120104 />
121105</LinearLayout>
@@ -126,13 +110,11 @@ ID to inflate the layout from the XML, as shown here:</p>
126110
127111<pre>
128112LayoutInflater inflater = getLayoutInflater();
129- View layout = inflater.inflate(R.layout.toast_layout ,
113+ View layout = inflater.inflate(R.layout.custom_toast ,
130114 (ViewGroup) findViewById(R.id.toast_layout_root));
131115
132- ImageView image = (ImageView) layout.findViewById(R.id.image);
133- image.setImageResource(R.drawable.android);
134116TextView text = (TextView) layout.findViewById(R.id.text);
135- text.setText("Hello! This is a custom toast! ");
117+ text.setText("This is a custom toast");
136118
137119Toast toast = new Toast(getApplicationContext());
138120toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
0 commit comments