0

I want to create on/off button with slide . I am using this Technic:

I put the buttons in the same position and one is visible and the other is hidden. and when I click on one the other button is appeared and the clicked is disappeared.

Now How can I make that button slide-able.

Here is the buttons: enter image description here

How can i do this ?

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
HK.avdalyan
  • 724
  • 1
  • 6
  • 21
  • 2
    You could use a [Switch](http://developer.android.com/reference/android/widget/Switch.html) (API > 14) as the base and create a custom version of it using you own graphics. – Remy Baratte Mar 26 '14 at 09:21
  • Slide on/off button -http://stackoverflow.com/questions/8150596/android-how-to-create-slide-on-off-button?rq=1 – sjain Mar 26 '14 at 09:28

1 Answers1

0

try using Switch but, if you are ok with minSdkVersion>=14.

hope following code helps you out.

In Layout Xml create a switch like:

<Switch
     android:id="@+id/on_off_switch"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textOff="OFF"
     android:textOn="ON"/>

Then in your activity get a switch from layout and set listener as follows,

Switch onOffSwitch = (Switch)  findViewById(R.id.on_off_switch); 
onOffSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(),"isChecked"+isChecked, Toast.LENGTH_LONG).show();
    }
});
Harshal Benake
  • 2,391
  • 1
  • 23
  • 40