时间:2010-07-25 13:17:22

标签: android spinner

4 个答案:

答案 0 :(得分:22)

答案 1 :(得分:10)

更改

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array,android.R.layout.simple_spinner_item);

ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.textview);

将仅更改微调器上默认可见的项目。如果我们需要在微调器中的所有项上应用相同的样式,我们需要更改

adapter.setDropDownViewResource(android.R.layout.simple_spinner_item)   to 


adapter.setDropDownViewResource(R.layout.textview);

答案 2 :(得分:4)

定义2 xml:R.layout.spinner_item,R.layout.spinner_dropdown_item

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:textSize="18sp" >
</TextView>

spinner_dropdown_item.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:ellipsize="marquee"
    android:textSize="18sp" />

--------------------------------更新-------------- ------------------------

其余代码:

final ActionBar actionBar = getActivity().getActionBar();
RelativeLayout relative = new RelativeLayout(getActivity());
Spinner spinner = new Spinner(getActivity());
spinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

relative.addView(spinner);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(relative);

// Set adapter and listener
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);

答案 3 :(得分:0)

设置android:scaleXanrdoid:scaleY似乎是一种更改微调器字体大小的简便方法。