Create beautiful toggle buttons in android

Rashi Karanpuria
4 min readJul 13, 2017

We don’t talk about toggle switches as often as we should. Toggle switches are these amazing UI components that provide functionality to switch between states, like pause and play, on and off, active and inactive. Imagine how messy it would have been if we had to do these with some other UI component like buttons or something.

Toggle switches in Android are great with onCheckedChangedListener to aid us in reacting to state changes. Toggle buttons are quite simple with text and light indicating whether it is checked or unchecked. SwitchCompats are beautiful slider like toggle buttons, and they give a kind of physical feel of sliding the thumb on and off.

Google material design SwitchCompat

I admit! I love changing states of a toggle switch by dragging the thumb. But sometimes we need more from toggle buttons, like marking an item favourite and not favourite. The basic version will look bland for that functionality. So how can we customise it to suit our needs, let’s explore!

As you would have guessed we would need a drawable of our own to customise the look and feel of our toggle button. And since there are two states we would actually need two drawables to distinguish between those two…

--

--