0

Is there anyway to disable tapping on the text of a Switch? Currently it toggles the switch which I don't want.

I'm setting my switch text like messageSwitch.setText("Messaging Enabled");. This makes the entire switch view receiving taps of the event. Is there any way to disable this?

Dunes Buggy
  • 1,779
  • 1
  • 21
  • 41

1 Answers1

0

In your xml, just set it like this:

android:clickable="false"

or this might be better

android:clickable="false"
android:focusable="false"
android:enabled="false"

Setting the enabled option to false disables both the text and the switch itself. You can do all of this programatically as well.

Janpan
  • 2,164
  • 3
  • 27
  • 53