(Information and examples taken from the DroidScript documentation)
Create buttons using the CreateButton method of the app object:
btn = app.CreateButton( text, width, height, options );
You can allow the button to auto-size by leaving out the dimensions or you can specify a width and height as decimal fractions. Setting the width and height to -1 whilst using the 'FillX' option will allow it to fill the layout width.
Use the SetOnTouch method of your button object to set the name of a function you want to be called when the button is touched.
Various button styles can be set by including a style name in the options parameter
Some controls use the same methods.
For examples of the same methods look here.
Method | Description |
---|---|
Button.GetAbsHeight() | |
Button.GetAbsWidth() | |
Button.GetHeight() | |
Button.GetPosition() | |
Button.GetText() | Fetches the recent caption (text) of a button. Returns a string. |
Button.GetTextSize( mode ) | |
Button.GetType() | |
Button.GetVisibility() | |
Button.GetWidth() | |
Button.SetFontFile( file ) | |
Button.SetHtml( html ) | |
Button.SetMargins( left,top,right,bottom ) | |
Button.SetOnTouch( callback ) | |
Button.SetPadding( left,top,right,bottom ) | |
Button.SetPosition( left, top, width, height ) | |
Button.SetScale( x,y ) | |
Button.SetSize( width, height ) | |
Button.SetStyle(color1,color2,radius,strokeClr,strokeWidth,shadow) | Used with Custom option |
Button.SetText( text ) | Changes the caption (text) displayed in a button to the given string value. Example: Button.SetText("This is a string."); |
Button.SetTextColor( colorcode ) | Sets the text color of a button. Use css-style color code, i.e. “#ffffff” for white. |
Button.SetTextShadow( radius,dx,dy,color ) | |
Button.SetTextSize( size,mode ) | |
Button.SetVisibility( HideShow ) | “Hide” hides the button without affecting the rest of the layout. “Show” displays the button. “Gone” hides the button totally, so that the layout will be rearranged. (See example below.) |
Options | Description |
---|---|
Alum | Display the Button in aluminum style |
FillX | Fill the layout width |
Gray | Display the Button in Gray Color |
NoSound | Play no sound, if the button will be touched |
Custom | Custom Buttons sample |
NoPad | Removes default padding of custom buttons |
FontAwesome | Use Font-Awesome icons |
Html | Enable HTML in button-text |
function OnStart() { lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); btn = app.CreateButton( "Press Me" ); btn.SetOnTouch( SayHello ); lay.AddChild( btn ); app.AddLayout( lay ); } function SayHello() { app.ShowPopup("Hello World!"); }
function OnStart() { lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); btn = app.CreateButton( "Press Me", 0.5, 0.2 ); btn.SetOnTouch( SayHello ); lay.AddChild( btn ); app.AddLayout( lay ); } function SayHello() { app.ShowPopup("Hello World!"); }
function OnStart() { lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); lay.SetPadding( 0.02, 0.02, 0.02, 0.02 ); btn = app.CreateButton( "Press Me", -1, -1, "FillX" ); btn.SetOnTouch( SayHello ); lay.AddChild( btn ); app.AddLayout( lay ); } function SayHello() { app.ShowPopup("Hello World!"); }
function OnStart() { lay = app.CreateLayout( "Linear", "Vertical,FillXY" ); lay.SetPadding( 0.1, 0.1, 0.1, 0 ); b1 = app.CreateButton( "Normal", -1, -1, "FillX" ); lay.AddChild( b1 ); b2 = app.CreateButton( "Gray", -1, -1, "FillX,Gray" ); lay.AddChild( b2 ); b3 = app.CreateButton( "Alum", -1, -1, "FillX,Alum" ); lay.AddChild( b3 ); app.AddLayout( lay ); }