Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a70c722c authored by Hemal Patel's avatar Hemal Patel Committed by Android (Google) Code Review
Browse files

Merge "Docs: Changed custom_toast to toast_layout" into nyc-docs

parents 3188f776 3b7309d7
Loading
Loading
Loading
Loading
+20 −11
Original line number Original line Diff line number Diff line
@@ -76,16 +76,22 @@ To nudge it down, increase the value of the last parameter.


<h2 id="CustomToastView">Creating a Custom Toast View</h2>
<h2 id="CustomToastView">Creating a Custom Toast View</h2>


<p>If a simple text message isn't enough, you can create a customized layout for your
<p>
toast notification. To create a custom layout, define a View layout,
  If a simple text message isn't enough, you can create a customized layout
in XML or in your application code, and pass the root {@link android.view.View} object
  for your toast notification. To create a custom layout, define a View
to the {@link android.widget.Toast#setView(View)} method.</p>
  layout, in XML or in your application code, and pass the root {@link

  android.view.View} object to the {@link android.widget.Toast#setView(View)}
<p>For example, you can create the layout for the toast visible in the screenshot to the right
  method.
with the following XML (saved as <em>toast_layout.xml</em>):</p>
</p>

<p>
  For example, you can create the layout for the toast visible in the
  screenshot to the right with the following XML (saved as
  <em>layout/custom_toast.xml</em>):
</p>
<pre>
<pre>
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout_root"
              android:id="@+id/custom_toast_container"
              android:orientation="horizontal"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_height="fill_parent"
@@ -105,13 +111,16 @@ with the following XML (saved as <em>toast_layout.xml</em>):</p>
&lt;/LinearLayout>
&lt;/LinearLayout>
</pre>
</pre>


<p>Notice that the ID of the LinearLayout element is "toast_layout_root". You must use this
<p>
ID to inflate the layout from the XML, as shown here:</p>
  Notice that the ID of the LinearLayout element is "custom_toast_container".
  You must use this ID and the ID of the XML layout file "custom_toast" to
  inflate the layout, as shown here:
</p>


<pre>
<pre>
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
View layout = inflater.inflate(R.layout.custom_toast,
                               (ViewGroup) findViewById(R.id.toast_layout_root));
                (ViewGroup) findViewById(R.id.custom_toast_container));


TextView text = (TextView) layout.findViewById(R.id.text);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");
text.setText("This is a custom toast");