2012-07-04 77 views
15

如何讓操作欄中的微調項目具有不同的項目(如操作欄頂部所示),然後是下拉列表中的項目? 例子是谷歌的郵件在操作欄微調:Android actionbar spinner selected item,subtitle and dropdown list

action_bar_pattern_spinner

  • 他們如何實現這個功能?
  • 我可以更改操作欄中的選定項目而不影響下拉列表中的相同項目嗎?
  • 他們如何將操作欄中的選定項目更改爲具有兩行和不同字體但不影響下拉列表中的項目?
  • 這是可能實現這與ICS和操作欄sherlock中的默認實現動作欄微調或我們應該嘗試自定義視圖?

任何源代碼,教程或文檔將非常有幫助。 我已經有操作欄中的適配器綁定微調框,我有下拉菜單中的列表,但我不能以任何方式修改項目,而不會影響下拉列表中的項目(因爲它們是相同的東西)。

回答

6

它可能是一個有點晚了,但評論代碼的教程就可以在Android開發者網站上找到: http://developer.android.com/guide/topics/ui/actionbar.html#Dropdown

的基礎是,在活動期間OnCreate中,你必須將其設置爲一個列表:

 getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 

然後創建一個微調適配器和幾個回調,就像你用普通微調器做的那樣。

希望它有助於

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); 
    } 
+0

是的,這是妥善解決。 – VladacusB

+4

是的,這就是他們如何做到的:[source](https://android.googlesource.com/platform/packages/apps/Calendar.git/+/d31b90f25456652b81be7c8349d7e10db1fa9338/src/com/android/calendar/CalendarViewAdapter.java) – Jay