I've been trying to customize the toggle button look but with no success. Here is how I want it to look like:
Can someone give me a tutorial?
I've been trying to customize the toggle button look but with no success. Here is how I want it to look like:
Can someone give me a tutorial?
I don't know if this is the best solution but it worked fine for me:
1.- Decide how big do you want the toggle button. In my case width 56dp and height 76dp.
2.- Create the icon set 56px-76px for mdpi, 84px-113px hdpi, same for xhdpi and xxhdpi
3.- Move the icons in the corresponding drawable folder. In my case 20 icons 5 in each folder, named ic_name1_on, ic_name1_off [...] ic_name5_off
4.- Create the following xml files in a new folder called drawable (if it does not exist yet):
5.- In ic_name1_toggle.xml the code must be:
6.- In ic_name1_toggle_bg.xml the code must be:
7.- Finally in your layout.xml:
I think you need to define a custom background for your button. Take a look at the Developer Guide on customizing a Button's background.
However, in step Three, Create a new XML file in the
res/drawable/ directory
Use this Xml:The element
android:state_checked="true"
is what defines that state as the checked background.Let me know if this works for you.
Create selector
and use it as background for your ToggleButton.
create toggle_selector.xml in res/drawable
apply the selector to your toggle button
Note: for removing the text i used following in above code