show

  • Revision slug: Extensions/Mobile/API/NativeWindow/toast/show
  • Revision title: show
  • Revision id: 468607
  • Created:
  • Creator: wesj
  • Is current revision? No
  • Comment

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

Optional options argument for the toast. Currently only a 'button' option is allowed.

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

<div 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.</div>
<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>
    <p>Optional options argument for the toast. Currently only a 'button' option is allowed.</p>
  </dd>
</dl>
<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