Buttons are an essential way to interact with and navigate through an app, and should clearly communicate what action will occur after the user taps them
Examples
To adapt the component to the style of the application it is often necessary to change its colors.
packagecom.totalcross;importtotalcross.ui.gfx.Color;importtotalcross.sys.Settings;importtotalcross.ui.Button;importtotalcross.ui.MainWindow;publicclassHelloWorldextendsMainWindow {privateButton btnRed;privateButton btnGreen;privateButton btnBlue;publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){ btnRed =newButton("Red");btnRed.setBackForeColors(Color.RED,Color.WHITE);add(btnRed, CENTER,CENTER ); btnGreen =newButton("Green");btnGreen.setBackForeColors(Color.GREEN,Color.WHITE);add(btnGreen, CENTER, AFTER ); btnBlue =newButton("Blue");btnBlue.setBackForeColors(Color.BLUE,Color.WHITE);add(btnBlue, CENTER,AFTER); }}
Full Button
Make the button the width of the screen.
packagecom.totalcross;importtotalcross.ui.gfx.Color;importtotalcross.sys.Settings;importtotalcross.ui.Button;importtotalcross.ui.MainWindow;publicclassHelloWorldextendsMainWindow {privateButton btnFull;publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI() { btnFull =newButton("Full Button");btnFull.setBackForeColors(Color.BLUE,Color.WHITE);add(btnFull, CENTER, CENTER, PARENTSIZE, PREFERRED); }}
Button shapes
Modify the button edges.
packagecom.totalcross;importtotalcross.ui.gfx.Color;importtotalcross.sys.Settings;importtotalcross.ui.Button;importtotalcross.ui.MainWindow;publicclassHelloWorldextendsMainWindow{privateButton btnRounded;privateButton btnBorderless;privateButton btnOutlined;publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){ btnRounded =newButton("Rounded Corners Button",Button.BORDER_ROUND);btnRounded.setBackForeColors(Color.BLUE,Color.WHITE);add(btnRounded, CENTER, CENTER ); btnBorderless =newButton("Borderless Button",Button.BORDER_NONE);btnBorderless.setBackForeColors(Color.BLUE,Color.WHITE);add(btnBorderless, CENTER, AFTER+5); btnOutlined =newButton("Outlined Button",Button.BORDER_OUTLINED);btnOutlined.setBackForeColors(Color.BLUE,Color.WHITE);add(btnOutlined, CENTER, AFTER+5); }}