Tutorial:

Step 1:
Open up Android Studio Project through res -> layout -> activity_main.xml (or) main.xml and add below code or just drag and drop the switch to design XML file

Step 2:

Add below code in MainActivity.kt.I have added ic_android_black_24dp from right click on drawable and select VectorAssets and add ic_android_black_24dp.

 

.