Skip to content

jzeferino/Xamarin.Android.SwitchButton

Repository files navigation

Build status NuGet

Xamarin.Android.SwitchButton

This is a Xamarin Android Binding for the SwitchButton.

This project provides you a convenient way to use and customise a SwitchButton widget in Android. With just resources changed and attrs set, you can create a lifelike SwitchButton of Android 5.0+, iOS, MIUI, or Flyme and so on.

Usage

Step 1

Install NuGet package.

Step 2

Define xmlns:app in your root view.

xmlns:sw="http://schemas.android.com/apk/res-auto"

Add the SwitchButton to your layout:

<com.kyleduo.switchbutton.SwitchButton
    android:id="@+id/sw"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    sw:kswThumbColor="@color/white"
    sw:kswThumbMargin="6dp"/>

Step 3

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    _switch = FindViewById<SwitchButton>(Resource.Id.sw);
    _switch.CheckedChange += (sender, e) => Toast.MakeText(this, $"isChecked {e.IsChecked}", ToastLength.Short).Show();
}  

Run and play with the sample.

License

MIT Licence

About

A customizable switch for Xamarin Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published