Skip to main content

Components

Switch

Control that allows users to turn on or off item

banner-Switch

Switch is component that allows the user to change a setting between two states. Switch usually used for settings, where the user can change the status setting to on or off. Switch is an alternative to the toggle button so that the android apps look more attractive.

switch android

Usage

There are 2 variants of Switch that we can use in Legion :

  1. Primary Switch. To implement the component, we use this tag LgnPrimarySwitch

  2. Secondary Switch. To implement the component, we use this tag LgnSecondarySwitch

The following is usage to implement Switch in XML

<com.telkom.legion.component.switch.LgnPrimarySwitch
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/dimen_16dp"
android:layout_marginTop="@dimen/dimen_16dp"
android:checked="true"
android:text="Primary Switch"/>
<com.telkom.legion.component.switch.LgnSecondarySwitch

Variant

There are 2 variants of Legion Switch :

  1. Primary Switch

  2. Secondary Switch

switch variant

Attribute

Attribute NameXml AttrsRelated method(s)Description
Textandroid:texttextTo set Text value directly via xml
Enable Statusandroid:enabledisEnableTo set enable or disable switch directly via xml
Checked Statusandroid:checkedisCheckedTo set checked status switch directly via xml

Example

The following is example usage for switch implementation

Static in xml

<com.telkom.legion.component.switch.LgnPrimarySwitch
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/dimen_16dp"
android:layout_marginTop="@dimen/dimen_16dp"
android:checked="true"
android:text="Primary Switch"/>
<com.telkom.legion.component.switch.LgnSecondarySwitch

Dynamic using Kotlin*

...
switchPry1.setOnCheckedChangeListener { view,isChecked ->
if(isChecked){
toast("Switch Legion Primary Checked")
}else{
toast("Switch Legion Primary Unchecked");
}
}


switch preview