Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add third state in Android Switch? [duplicate]

I am trying to write an Android code to create three states for an Android Switch. Three state means ON - Default - OFF.

When I will open my app , the Switch will be in default mode and the button will be in centre. When I will drag the switch into left side then the state will change to ON and when I will drag to right side then the state will change to OFF.

In Android Switch , we have two state ON/OFF. I am not able to find any technique to add third state into the switch.

How can I add the third state in Android Switch?

like image 240
MyProg Avatar asked May 09 '14 06:05

MyProg


People also ask

How do I change the switch size on my Android?

Using scale property to change size worked for me. Add these lines to your <switch/> tag in xml file. You can change scale value as per your need. Here value 2 makes it double in size, similarly value 0.5 makes it half in size.

Which of the following are methods of toggle button?

Since the Android 4.0 version (API level 14), it has another type of toggle button called switch which provides user slider control. Programmatically, isChecked() method is used to check the current state of the toggle button. This method returns a boolean value.


1 Answers

You could make a custom control based on the Android Switch control that has the 3 states you want.

You can find some info here:

http://developer.android.com/guide/topics/ui/custom-components.html

Tutorial:

http://www.tutorialspoint.com/android/android_custom_components.htm

I'd personally take the approach used in the tutorial. Just extend from the switch class in your 3 state switch and try to override the states to add a third one.

like image 81
Speedy Codezales Avatar answered Nov 04 '22 03:11

Speedy Codezales