Android 简单微调器下拉项
Android Simple Spinner Dropdown Item
在我的 android 应用程序中,我使用微调器来呈现国家/地区的名称。以下是我的代码:
XML
<Spinner
android:id="@+id/intCountry"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="38dp"
android:background="#FFFFFF"
android:entries="@array/intCountry"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
Java - 版本 1
//Country Spinner
country = (Spinner) findViewById( R.id.intCountry );
String[] countries = getResources().getStringArray( R.array.intCountry );
ArrayAdapter<String> countryAdapter = new ArrayAdapter<>( this, R.layout.support_simple_spinner_dropdown_item, countries );
countryAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
country.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selCountry = (String) parent.getItemAtPosition(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
} );
Java - 版本 2
//Country Spinner
country = (Spinner) findViewById( R.id.intCountry );
ArrayAdapter<CharSequence> countAdapter = ArrayAdapter.createFromResource( this,R.array.intCountry,android.R.layout.simple_spinner_dropdown_item );
countAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
country.setAdapter( countAdapter );
country.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selCountry = (String) parent.getItemAtPosition(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
} );
这两个选项都呈现一个简单而精简的 select 选项弹出窗口。我正在尝试使用单选按钮样式 select 选项导出全屏 select 选项。
我得到的结果如下:
我要的是这个:
试试这个代码段,下面的代码行将在您的微调器值中设置单选按钮
yourAdapterInstance.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);
对于全屏模式,您可以在 xml 文件中设置此属性
android:spinnerMode="dialog" // This will open spinner items in dialog.