在操作栏之外的下拉旋转器?(IceCream三明治风格,带ActionBarSherlock)

Ahm*_*mad 12 android android-theme actionbarsherlock android-actionbar

有没有办法为Android 2.3.3创建Dropdown Spinner?我正在使用ActionbarSherlock.

这是我的意思的一个例子:

在此输入图像描述

谢谢

dmo*_*mon 26

就目前而言,你很幸运.它可以使用ActionBarSherlock完成,它适用于4.0之前的版本.但是,我并不是百分之百确定Jake Wharton会希望我们这样使用它,因为它不完全是"公共api",AFAIK(我想要问).无论如何,您必须首先创建自己的类以从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);

  }
}
Run Code Online (Sandbox Code Playgroud)

要将其包含在布局中:

<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"/>
Run Code Online (Sandbox Code Playgroud)

现在您必须创建自定义SpinnerAdapter,并且需要覆盖以下方法以获得正确的外观:

@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;
  }
Run Code Online (Sandbox Code Playgroud)

YMMV,尤其是 关于主题.