How to set the default value of the switch widget in android
AndroidXmlAndroid Problem Overview
I am coding my xml file with the couple switch widgets. but I don't know how to set the default value of them as ON. And I just want to get this problem solved within the xml file so no Java.
Android Solutions
Solution 1 - Android
To make Switch set "ON" in you XML file use this:
android:checked="true"
Solution 2 - Android
To set the Switch default as ON in XML file :
android:checked = "true"
Don't try using android:pressed = "true" . It will throw an error while running the app.
Solution 3 - Android
You can set the Switch default as ON/OFF from the code itself. Try something like this:
switch.setChecked(true) // to set it true
Or,
switch.setChecked(false) // to set it false