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]
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ParentLayoutClicked"
android:focusable="false"
android:orientation="horizontal" >
<Switch
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:id="@+id/switch_internet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="NOT CONNECTED"
android:textOn="CONNECTED"
android:focusable="false"
android:layout_alignParentRight="true"
android:text="@string/s_internet_status" />
</RelativeLayout>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…