Button widget is a UI element that is used to trigger any actions. These actions can be navigating to another form, perform animations, interacting with a dialog box, etc.
A button displays text with a background image or a background color.
Button widget is employed in many scenarios where the user performs an on-click action on a button. Some of them are:
Navigation: The previous and next buttons are used in applications to navigate to the previous form or next form.
Dialog Box: Buttons are employed in dialog boxes to enable interaction between the user and the application.
Modify Properties of other widgets: Button can modify properties of other widgets in the form, with an on-click action.
Invoke Services: You can get data from the backend into the form, with an on-click action of a button. For instance, consider a form that contains a segment to be populated with employee details from the backend. A button in the form can be given an on-click action to invoke the services.
Perform Animations: You can animate other widgets to move, rotate or scale using a button widget. The most common use case for this is the Hamburger menu. You can click on a hamburger menu to move a container which is not in the device frame to the visible area.
Widgets are normally added to your Kony application using Kony Visualizer, but can also be added from code. For general information on using widgets in Visualizer, see Designing an Application in the Kony Visualizer User Guide.
For general information on the Button widget see the Button topic in the Kony Visualizer User Guide.
The Button widget capabilities can be broadly categorized into the following:
Events | Description |
---|---|
doLayout |
Invoked for every widget when the widget position and dimensions are computed. |
Properties | Description |
---|---|
anchorPoint | Specifies the anchor point of the widget bounds rectangle using the widget's coordinate space. |
bottom | Determines the bottom edge of the widget and is measured from the bottom bounds of the parent container. |
contentAlignment | Specifies the alignment of the text for a widget with respect to its boundaries. |
centerX | Determines the center of a widget measured from the left bounds of the parent container. |
centerY | Determines the center of a widget measured from the top bounds of the parent container. |
height | Determines the height of the widget and measured along the y-axis. |
left | Determines the lower left corner edge of the widget and is measured from the left bounds of the parent container. |
maxHeight | Specifies the maximum height of the widget and is applicable only when the height property is not specified. |
maxWidth | Specifies the maximum width of the widget and is applicable only when the width property is not specified. |
minHeight | Specifies the minimum height of the widget and is applicable only when the height property is not specified. |
minWidth | Specifies the minimum width of the widget and is applicable only when the width property is not specified. |
padding | Defines the space between the content of the widget and the widget boundaries. |
paddingInPixel | Indicates if the padding is to be applied in pixels or in percentage. |
right | Determines the lower right corner of the widget and is measured from the right bounds of the parent container. |
top | Determines the top edge of the widget and measured from the top bounds of the parent container. |
width | Determines the width of the widget and is measured along the x-axis. |
zIndex | Specifies the stack order of a widget. |
Properties | Properties |
---|---|
backgroundColor | Specifies the background color of the widget in hex format. |
blockedUISkin | Specifies the skin that must be used to block the interface until the action in progress (for example, a service call) is completed. |
clipView | Defines a shape to clip the widget view. |
focusSkin | Specifies the look and feel of the Button when in focus. |
glowEffect | Specifies if there must be glow effect when you touch the button. |
hoverSkin | Specifies the look and feel of a widget when the cursor hovers on the widget. |
pressedSkin | Specifies the skin to indicate that the Button is pressed or clicked. |
rippleBackground | Defines the ripple background for a Button Widget. |
shadowDepth | Defines the depth of the shadow effect applied to the Button Widget. |
shadowType | Sets a type of the shadow effect to apply to the Button Widget. |
showProgressIndicator | Specifies if the progress indicator must be displayed when the button is clicked. |
Methods | Description |
---|---|
animate | Applies an animation to the widget. |
Properties | Description |
---|---|
transform | Contains an animation transformation that can be used to animate the widget. |
widgetSwipeMove | Used to enable and configure the left or right swipe actions for a widget. |
Methods | Description |
---|---|
clone | When this method is used on a container widget, then all the widgets inside the container are cloned. |
Properties | Description |
---|---|
cacheConfig | Used to configure the cachePolicy and storagePolicy of the cache responses. |
Methods | Description |
---|---|
registerForPeekandPop | Registers a widget to enable 3D Touch peek and pop gestures. |
setOnPeek | Sets and overrides the existing onPeekCallback for the widget. |
setOnPop | Sets and overrides the existing onPopCallback for the widget. |
unregisterForPeekandPop | Unregisters a widget from 3D Touch peek and pop gestures. |
Events | Description |
---|---|
onClick | An event callback is invoked by the platform when the user performs a click action on the button. |
onScrollWidgetPosition | An event callback is invoked by the platform when the widget location position gets changed on scrolling. |
onTouchEnd | An event callback is invoked by the platform when the user touch is released from the touch surface. |
onTouchMove | An event callback is invoked by the platform when the touch moves on the touch surface continuously until movement ends. |
onTouchStart | An event callback is invoked by the platform when the user touches the touch surface. |
Methods | Description |
---|---|
addGestureRecognizer | Allows you to set a gesture recognizer for a specified gesture for a specified widget. |
removeGestureRecognizer | Allows you to remove the specified gesture recognizer for the specified widget. |
setGestureRecognizer | Allows you to set a gesture recognizer for a specified gesture for a specified widget. |
Properties | Description |
---|---|
retainContentAlignment | Helps to retain the content alignment of the widget while applying RTL. |
retainFlexPositionProperties | Helps to retain the left, right and padding properties while applying RTL. |
retainFlowHorizontalAlignment | Enables you to change the horizontal flow of the widget from left to right. |
Methods | Description |
---|---|
getBadge | Enables you to read the badge value (if any) attached to the specified widget. |
setBadge | Enables you to set the badge value to the given widget at the upper, right corner of the widget. |
setCursor | Applies to all widgets for the Windows Desktop channel. Customizes the cursor when hovered on widgets. |
Properties | Description |
---|---|
buttonType | Supports native iOS button types. |
contextMenu | Used add a menu that appears upon clicking a button. |
cursor | Enables you to control the cursor property for the Windows Desktop channel. |
cursorType | Specifies the type of mouse pointer used. |
customCursor | Enables you to configure a custom cursor for Windows Desktop channel. |
enableHapticFeedback | Allows you to enable or disable haptic feedback on the Button widget. |
externalURL | Specifies that the URL must be opened directly from the web site without having to contact the Kony Server. |
nativeButtonFocusImage | Allows you to set an image to be used when the button has focus. |
nativeButtonNormalImage | Allows you to set an image to be used for a button. |
rawBytes | Specifies the rawbytes representing an image that can be used as a background for the button. |
text | Specifies a general or descriptive text for the Button widget. |
toolTip | Specifies the hint text when the cursor hovers over a widget, without clicking it. |
Methods | Description |
---|---|
blur | Enables you to make the widget look unfocused. |
convertPointFromWidget | Allows you to convert the coordinate system from a widget to a point (receiver's coordinate system). |
convertPointToWidget | Allows you to convert the co-ordinate system from point(receiver's co-ordinate system) to a Widget. |
removeFromParent | Allows you to remove a child widget from a parent widget. |
setEnabled | Specifies the widget that must be enabled or disabled. Syntax |
setFocus | Specifies the widget on which there must be focus. |
Use this method to set the visibility of the widget. |
Properties | Description |
---|---|
enableCache | Enables you to improve the performance of Positional Dimension Animations. |
info | A custom JSObject with the key value pairs that a developer can use to store the context with the widget. |
isVisible | Controls the visibility of a widget on the form. |
parent | Helps you access the parent of the widget. |
Events | Description |
---|---|
postOnclickJS | Allows the developer to execute custom JavaScript function after the onClick callback of the widget is invoked. |
preOnclickJS | Allows the developer to execute custom JavaScript function before the onClick callback of the widget is invoked. |
var button1 = new kony.ui.Button(basicConf, layoutConf, pspConf);
Note: The configuration properties should be passed only in the respective configuration objects otherwise they are ignored
Example
//The below function is the callback function for onClick event call. function onClickCallBack() { //Write your logic here. } //Defining the button with onClick:onClickCallBck. var btnBasic = { id: "Onbutton", isVisible: true, skin: "btnSkin", focusSkin: "btnFSkin", text: "Click Here", onClick: onClickCallBck }; var btnLayout = { containerWeight: 100, padding: [5, 5, 5, 5], margin: [5, 5, 5, 5], hExpand: true, vExpand: false, displayText: true }; var btnPSP = { pressedSkin: "presSkin", externalURL: "https://www.kony.com",
submitURL: "https://www.kony.com",
glowEffect:true
}; //Creating the button. var Onbutton = new kony.ui.Button(btnBasic, btnLayout, btnPSP);
You can customize the appearance of the button using the following properties:
The Button Widget has the following considerations:
prem | Copyright © 2012 Kony, Inc. All rights reserved. |
prem | Copyright © 2012 Kony, Inc. All rights reserved. |