15

如何使操作栏中的微调器选择不同的项目(显示在操作栏顶部)然后是下拉列表中的项目?示例是操作栏中带有微调器的谷歌邮件:

action_bar_pattern_spinner

  • 他们是如何实现这个功能的?
  • 我可以更改操作栏中的选定项目而不影响下拉列表中的相同项目吗?
  • 他们如何将操作栏中的选定项目更改为具有两行和不同字体但不影响下拉列表中的项目?
  • 这是否可以通过 ICS 和操作栏 sherlock 中的操作栏微调器的默认实现来实现这一点,还是我们应该尝试使用自定义视图?

任何源代码、教程或文档都会非常有帮助。我已经在操作栏中有带适配器的绑定微调器,并且我在下拉菜单中有列表,但是我不能以任何方式修改项目而不影响下拉列表中的项目(因为它们是相同的)。

4

2 回答 2

20

要在操作栏微调器中获得与微调器列表中不同的视图,您可以使用BaseAdapter或 ArrayAdapter 并覆盖一些方法:

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // Return a view which appears in the action bar.

    return yourCustomView..;
  }

  @Override
  public View getDropDownView(int position, View convertView, ViewGroup parent) {
    // Return a view which appears in the spinner list.

    // Ignoring convertView to make things simpler, considering
    // we have different types of views. If the list is long, think twice!
    return super.getView(position, null, parent);
  }
于 2012-07-31T13:59:59.373 回答
6

it might be a bit too late, but the tutorial with commented codes can be found on the Android developer website: http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown

the basics is that during the activity OnCreate you have to set it to be a list:

      getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

and then create a spinner adapter and a couple of callbacks just like you would do with a normal spinner.

hope it helps

于 2012-07-30T11:15:38.930 回答