show

  • Revision slug: Mozilla/Add-ons/Firefox_for_Android/API/NativeWindow/toast/show
  • Revision title: show
  • Revision id: 501261
  • Created:
  • Creator: wbamberg
  • Is current revision? Yes
  • Comment Moved From Extensions/Mobile/API/NativeWindow/toast/show to Mozilla/Add-ons/Firefox_for_Android/API/NativeWindow/toast/show

Revision Content

  • The NativeWindow object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

Summary

NativeWindow.toast.show() displays a toast notification on Firefox for Android.

A toast notification is a message that appears on the screen for a set interval and then fades away. It does not accept user input.

Syntax

NativeWindow.toast.show(message, duration);

message
The message displayed by the toast.
duration

How long the toast should appear before fading away. This can take one of two values, short or long.

options
A set of options for the toast. See the "Supported options" section below

Supported options

button {{ gecko_minversion_inline("24.0") }}

Attribute Description
label The label for the button. This text won't be formatted like a link. Keep it a short single word to make it feel clickable.
icon An icon for the button. This can be a base64 encded url, a chrome/resource url, or a drawable url.
callback A callback that is called when you tap the icon. The function isn't passed any arguments.

Example

In the example below, an add-on adds a menu item that displays a toast:

function showToast(window) {  
  window.NativeWindow.toast.show("Showing you a toast", "short", {
    button: {
      label: "Undo",
      icon: "drawable://alert_app",
      callback: function() {
        Services.prompts.alert("You clicked the button");
      }
    }
  });  
}  
      
var menuID;  
      
function addMenuItem(window) {  
  menuID = window.NativeWindow.menu.add("Show Toast", null, function(){  
    showToast(window);   
  });  
}  
      
function removeMenuItem(window) {  
  window.NativeWindow.menu.remove(menuID);  
}

See Also

Revision Source

<ul>
  <li class="note">The <a href="/en/Extensions/Mobile/API/NativeWindow" title="https://developer.mozilla.org/en/DOM/window.NativeWindow">NativeWindow</a> object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.</li>
</ul>
<h2 id="Summary" name="Summary">Summary</h2>
<p><code><a href="/en/Extensions/Mobile/API/NativeWindow/toast" title="en/DOM/window.NativeWindow.toast">NativeWindow.toast</a>.show()</code> displays a <a class="link-https" href="https://developer.android.com/guide/topics/ui/notifiers/toasts.html" title="https://developer.android.com/guide/topics/ui/notifiers/toasts.html">toast notification</a> on <a href="/en/Mozilla/Firefox_for_Android" title="en/Mozilla/Firefox_for_Android">Firefox for Android</a>.</p>
<p>A toast notification is a message that appears on the screen for a set interval and then fades away. It does not accept user input.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<p><em><code>NativeWindow.toast.show(message, duration);</code></em></p>
<dl>
  <dt>
    <code>message</code></dt>
  <dd>
    The message displayed by the toast.</dd>
  <dt>
    <code>duration</code></dt>
  <dd>
    <p>How long the toast should appear before fading away. This can take one of two values, <code>short</code> or <code>long</code>.</p>
  </dd>
  <dt>
    <code>options</code></dt>
  <dd>
    A set of options for the toast. See the "Supported options" section below</dd>
</dl>
<h2 id="Supported_options">Supported options</h2>
<h3 id="button"><code>button </code> {{ gecko_minversion_inline("24.0") }}</h3>
<table class="standard-table">
  <tbody>
    <tr>
      <td class="header">Attribute</td>
      <td class="header">Description</td>
    </tr>
    <tr>
      <td><code>label</code></td>
      <td>The label for the button. This text won't be formatted like a link. Keep it a short single word to make it feel clickable.</td>
    </tr>
    <tr>
      <td><code>icon</code></td>
      <td>An icon for the button. This can be a base64 encded url, a chrome/resource url, or a drawable url.</td>
    </tr>
    <tr>
      <td><code>callback</code></td>
      <td>A callback that is called when you tap the icon. The function isn't passed any arguments.</td>
    </tr>
  </tbody>
</table>
<h2 id="Example" name="Example">Example</h2>
<p>In the example below, an add-on adds a menu item that displays a toast:</p>
<pre class="deki-transform">
function showToast(window) { &nbsp;
  window.NativeWindow.toast.show("Showing you a toast", "short", {
    button: {
      label: "Undo",
      icon: "drawable://alert_app",
      callback: function() {
        Services.prompts.alert("You clicked the button");
      }
    }
  }); &nbsp;
} &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
var menuID; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
function addMenuItem(window) { &nbsp;
&nbsp; menuID = window.NativeWindow.menu.add("Show Toast", null, function(){ &nbsp;
&nbsp;&nbsp;&nbsp; showToast(window);&nbsp; &nbsp;
&nbsp; }); &nbsp;
} &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
function removeMenuItem(window) { &nbsp;
&nbsp; window.NativeWindow.menu.remove(menuID); &nbsp;
}
</pre>
<h2 id="Specification" name="Specification">See Also</h2>
Revert to this revision