动作条以外的下拉微调? (冰淇淋三明治风格,W / ActionBarSherlock) [英] Dropdown Spinner outside of actionbar? (IceCream Sandwich style, w/ActionBarSherlock)

查看:125
本文介绍了动作条以外的下拉微调? (冰淇淋三明治风格,W / ActionBarSherlock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来创建一个下拉微调为Android 2.3.3?我使用ActionbarSherlock。

Is there a way to create a Dropdown Spinner for Android 2.3.3? I am using ActionbarSherlock.

下面是我的意思为例:

感谢

推荐答案

既然这样,你很幸运。它可以与ActionBarSherlock完成,并且它与版本pre-4.0。不过,我不是100%肯定杰克·沃顿希望我们能够使用这样的,因为它不完全公共的API,AFAIK(我是问)。无论如何,你必须首先创建你自己的类,从ActionBarSherlock类扩展:

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);

  }
}

要包括它的布局:

<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"/>

现在你需要创建一个自定义的 SpinnerAdapter ,你需要重写下面的方法来获得适当的外观:

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;
  }

因人而异,ESP。关于主题。

YMMV, esp. regarding the themes.

这篇关于动作条以外的下拉微调? (冰淇淋三明治风格,W / ActionBarSherlock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆