Search code examples
androidswitchcompat

How to show process status on a switch in android?


In the material design guide there is a section called "Display processing status" where we see a video of a Switch with a progress indicator on the thumb.

https://material.io/design/components/selection-controls.html#switches

Because a switch shows the actual status of something, sometimes there is a delay in its change of state. In such cases, a processing status animation can be used.

A processing status is an animation on the thumb of the switch. For example, it can be used when a switch that controls a hardware feature experiences a delay before its final status can be confirmed.

How can I achieve such an effect? is that part of the normal CompatSwitch? Is there a library that does this?


Solution

  • This is just an idea that may help you. You can use the custom image/drawable inside switches with help of switch thumb property

    <Switch
    android:id="@+id/switch_one"
    . . .
    android:track="@drawable/switch_track_custom"
    android:thumb="@drawable/switch_thumb_custom"/>
    

    For state change, you can use Selecter. this blog gives you a good idea.

    Here are some other blog and libraries