布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
字符串
<string-array name="spinnername">
<item>中文</item>
<item>俄语</item>
</string-array>
代码实现
val mItems=resources.getStringArray(R.array.spinnername)
// Create an ArrayAdapter using a simple spinner layout and languages array
val aa = ArrayAdapter(this, android.R.layout.simple_spinner_item, mItems)
// Set layout to use when the list of choices appear
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
//Set Adapter to Spinner
spinner!!.setAdapter(aa)
编译并运行模拟器
按箭头操作
成功显示