As it stands, you're in luck. It can be done with ActionBarSherlock and it works with versions pre-4.0 . However, I'm not 100% sure Jake Wharton will want us to use it like this, since it's not exactly "public api", AFAIK (I've meant to ask). Anyway, you have to first create your own class to extend from the ActionBarSherlock class:
public class MyIcsSpinner extends IcsSpinner {
public MyIcsSpinner(Context context, AttributeSet attrs) {
super(context, attrs, com.actionbarsherlock.R.attr.actionDropDownStyle);
}
public MyIcsSpinner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
}
To include it in a layout:
<com.blah.blah.blah.MyIcsSpinner
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:textAllCaps="true"
android:background="@drawable/abs__spinner_ab_holo_light"
android:textColor="#000000"
android:gravity="center"/>
Now you have to create a custom SpinnerAdapter
, and you need to override the following methods to get the proper look and feel:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final TextView filterName;
if (convertView == null) {
filterName = (TextView) layoutInflater.inflate(R.layout.filter_item, parent, false);
} else {
filterName = (TextView) convertView;
}
filterName.setText(getItem(position));
return filterName;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
final TextView filterName;
if (convertView == null) {
filterName = (TextView) layoutInflater.inflate(R.layout.sherlock_spinner_dropdown_item, parent, false);
filterName.setEllipsize(TruncateAt.END);
} else {
filterName = (TextView) convertView;
}
filterName.setText(getItem(position));
return filterName;
}
YMMV, esp. regarding the themes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…