1

The switch button that android has is really cool. I want to have the switch change states only through the only the sliding motion. What I don't want it to do is to change states when just tapping the switch. I would also like to be able to keep the nice sliding animation in tact. Does anyone know how to do this?

Regards

Developers Park
  • 187
  • 1
  • 11

1 Answers1

0

You can achieve this by ensuring the switch is not clickable

 android:clickable="false"

and then adding touch listener that passes touch events to the switch

        final Switch switch = 
                   (Switch) rootView.findViewById(R.id.lock_switch);
        if (switch != null) {
            // This combined with android:clickable="false"
            // makes this a slide only switch
            switch.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch.onTouchEvent(event);
                    return true;
                }
            });
        }
grantnz
  • 7,322
  • 1
  • 31
  • 38