Search code examples
androidswipe-gesture

How to create a three way switch in android like google TEZ app?


I'm trying to create a switch,which on swipe up will have to perform an intent and on swipe down should start another intent.the problem now is,I couldn't show the movement of switch up and down.Can anyone help to show the switch movement on swiping(example google Tez App)


Solution

  • There is no standard UI element which will has 3 toggle state. However if you want to implement it you can design your own.

    You can think of a Seekbar. Seekbar has same type of slider. You can customize the slider as per your need.

    • Using .setMax(2); which means that the seekbar has only 3 positions/steps.
    • Using .setProgress(1); will set the starting position of the seekbar.
    • progressChanged(..) method you can change the drawable background with .setBackgroundDrawable(...) and even you can customize the thumb(Switch like circle button) by setting image as .setThumb(...)
    • If you even want to change the position of the slider you can implement a Click event handling and there change the position of the slider with .setProgress(); and if progress equals the fixed value (as there are only 3 possible values) perform your required operation.

    P.S: I think this could be achieved by the above steps, as there are no standard UI element for the one you asked.. Hope it helps.