Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Cihan Kaptan
7,493 PointsHow to change style of Switch Button basicly ?
I have a two image for on , off selection I tried to put then a selection part but I couldnt managed :/
1 Answer
Afik Paryente
2,042 PointsIt's very simple.
- Create directory called "drawable" in your "res" directory. (If you dont have one already). 2.Creat a new XML file, name it however you want. Root element (if needed) should be 'selector'.
-
Understand the following code and use it:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/on" android:state_checked="true"/> //the drawable to be displayed when view is checked. <item android:drawable="@drawable/off" android:state_checked="false"/>//the drawable to be displayed when view is not checked. </selector>
The code is fairly easy to understand... Repley me if you havent. Now, you can just use this xml file as the background of your SwitchButton.