项目作者: akamud

项目描述 :
Xamarin bindings for MaterialSpinner by @ganfra
高级语言: C#
项目地址: git://github.com/akamud/MaterialSpinner-Xamarin.git
创建时间: 2015-09-23T02:02:00Z
项目社区:https://github.com/akamud/MaterialSpinner-Xamarin

开源协议:MIT License

下载


MaterialSpinner-Xamarin


Xamarin bindings for MaterialSpinner by @ganfra

Spinner with Material Design - Down to API 9

This library provides you a Spinner with the Material style. You can use it like any regular Spinner. Add floating label text, hint and error messages.

Installing


NuGet package available:

  1. PM> Install-Package MaterialSpinner-Xamarin

Usage

There is a sample project available here

Using in a XML:

  1. <fr.ganfra.materialspinner.MaterialSpinner
  2. android:id="@+id/spinner"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. app:ms_multiline="false"
  6. app:ms_hint="hint"
  7. app:ms_enableFloatingLabel="false"
  8. app:ms_enableErrorLabel="false"
  9. app:ms_floatingLabelText="floating label"
  10. app:ms_baseColor="@color/base"
  11. app:ms_highlightColor="@color/highlight"
  12. app:ms_errorColor="@color/error"
  13. app:ms_typeface="typeface.ttf"
  14. app:ms_thickness="2dp"
  15. app:ms_hintColor="@color/hint"
  16. app:ms_arrowColor="@color/arrow"
  17. app:ms_arrowSize="16dp"
  18. app:ms_alignLabels="false"
  19. app:ms_floatingLabelColor="@color/floating_label"></fr.ganfra.materialspinner.MaterialSpinner>

You can set a hint and a floating label text. If no floating label text is provided, the hint will be set instead.

You use it like a regular spinner, setting an adapter to it:

  1. string[] ITEMS = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"};
  2. var adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleSpinnerItem, ITEMS);
  3. adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
  4. var spinner = FindViewById<MaterialSpinner>(Resource.Id.spinner1);
  5. spinner.Adapter = adapter;

If you need to set an error message, you can do it the same way as an EditText:

  1. // Activate
  2. spinner.Error = "Error";
  3. // Deactivate
  4. spinner.Error = null;

You can choose to have a scrolling animation or to set the error message on multiple lines with the ms_multiline attribute in XML (default is true).

Gif example

License

MIT License