Xamarin Android 下拉列表

时间:2022-07-21 13:44:57
<Spinner android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner);
var adapter = ArrayAdapter.CreateFromResource(
this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>