Khi đứng, bạn đang ở may mắn. Nó có thể được thực hiện với ActionBarSherlock và nó hoạt động với các phiên bản trước 4.0. Tuy nhiên, tôi không chắc chắn 100% Jake Wharton sẽ muốn chúng tôi sử dụng nó như thế này, vì nó không chính xác là "api công cộng", AFAIK (tôi muốn hỏi). Dù sao, trước tiên bạn phải tạo lớp của riêng bạn để mở rộng từ lớp ActionBarSherlock:
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);
}
}
Để đưa nó vào trong một bố cục:
<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"/>
Bây giờ bạn có để tạo ra một tùy chỉnh SpinnerAdapter
, và bạn cần để ghi đè các phương pháp sau đây để có giao diện phù hợp:
@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, đặc biệt. về các chủ đề.
Làm cách nào để thả xuống [Spinner] (http://developer.android.com/reference/android/widget/Spinner.html) đã có từ API 1? Các chủ đề có thể khác nhau, nhưng bạn sẽ có thể sao chép hầu hết các chủ đề đó thành một chủ đề tùy chỉnh. – Sam
Anh ấy có nghĩa là giao diện của người quay ICS, nơi họ "thả xuống" thay vì là hộp thoại. – dmon