DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


tips_tricks:menubutton

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tips_tricks:menubutton [2015/02/28 18:36] (current)
stevegarman created
Line 1: Line 1:
 +===== 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 =====
 +<code JavaScript 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();​ 
 +}  
 +
 +</​code>​
tips_tricks/menubutton.txt · Last modified: 2015/02/28 18:36 by stevegarman