User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

tips_tricks:menubutton

Can't use the phone's menu button?

Things are not quite as straightforward with android menu buttons as they used to be.

How it used to work

Each android phone came with a menu button.

When the user pressed it, the appropriate menu was displayed.

app.SetMenu is supplied to define the appropriate menu(s) in your app.

But my phone/tablet has no menu button

Unfortunately, it is becoming much more common for devices not to provide a menu button.

How to show the menu anyway

app.ShowMenu() can be used from your code to display the menu.
The most appropriate way to call this is usually from a button.

However, if you are very short of screen space, it may be easier to hijack the device's Back Button instead.

If you do this, don't forget to leave a way to exit the app.

Some sample code is included here to show a way to do this.

Sample code

backButtonMenu.js
//Called when application is created.  
function OnStart()
{     
    app.SetMenu( "Exit,Model,Display" );  
    app.EnableBackKey( false );  
    app.ShowPopup ( "Back key emulates Menu key" ); 
}  
 
//Called when user selects a menu item.  
function OnMenu( name )
{           
    if ( name == "Exit" ) app.Exit() ; 
    if ( name == "Model" ) app.ShowPopup( app.GetModel() ); 
    if ( name == "Display" ) 
    {
        var s = app.GetDisplayWidth() + " x " + app.GetDisplayHeight();
        app.ShowPopup( s );
    }
}  
 
//Called when the back key is pressed.  
function OnBack()
{ 
  app.ShowMenu(); 
}  
tips_tricks/menubutton.txt · Last modified: 2015/03/01 02:36 (external edit)