I have a switch
button (actually is a custom one) and I want to disable the swipe functionality for some reason; I want the user to be able to click it only. Is
You can setClickable(false) to your Switch, then listen for the onClick() event within the Switch's parent and toggle it programmatically. The switch will still appear to be enabled but the swipe animation won't happen.
...
[In onCreate()]
Switch switchInternet = (Switch) findViewById(R.id.switch_internet);
switchInternet.setClickable(false);
...
[click listener]
public void ParentLayoutClicked(View v){
Switch switchInternet = (Switch) findViewById(R.id.switch_internet);
if (switchInternet.isChecked()) {
switchInternet.setChecked(false);
} else {
switchInternet.setChecked(true);
}
}
...
[layout.xml]