Skip to content

Instantly share code, notes, and snippets.

@MaartenS
Last active February 16, 2016 09:18
Show Gist options
  • Select an option

  • Save MaartenS/d41bc6f4fbec3a13eb01 to your computer and use it in GitHub Desktop.

Select an option

Save MaartenS/d41bc6f4fbec3a13eb01 to your computer and use it in GitHub Desktop.
Android switch/ toggle button/slider

####view

<android.support.v7.widget.SwitchCompat
        android:id="@+id/Switch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textOff=""
        android:text="Toggle Switch"
        android:background="@android:color/transparent"
        android:textColor="@color/secondary_text"
        android:textOn=""
        android:button="@null"
        android:padding="20dp"/>

####activity/ fragment

swt = (SwitchCompat)findViewById(R.id.Switch);
swt.setOnCheckedChangeListener (this);
swt.setChecked (true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment