簡體   English   中英

在動作欄中顯示所有標簽嗎?

[英]Showing all tabs in action bar sherlock?

我使用動作欄夏洛克,在橫向模式下,所有選項卡均顯示,但在縱向模式下,僅顯示一個。

如何顯示所有選項卡,以便用戶可以沿着它們滑動? 他們不必同時在屏幕上,我只是不想彈出菜單。

一個有點老的問題,您可能已經想出了解決方法,但是這是一個為遇到同樣問題的人(像我一樣)掙扎的解決方案。 實際上, 文檔中指出以下內容:

注意:在某些情況下,Android系統會將操作欄標簽顯示為下拉列表,以確保最適合操作欄。

為了避免選項卡項不適合屏幕時的下拉列表,請將選項卡添加到ActionBar並添加項設置導航模式。

ActionBar bar = getSupportActionBar();
//bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Don't set navigation mode yet, if you do then portrait mode will revert to list mode if tab items don't fit the screen
bar.setLogo(logo);
bar.setHomeButtonEnabled(false);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowTitleEnabled(false);

// Add lots of tab items
for (int i = 0; i < channels.length; i++) {
    ActionBar.Tab tab = bar.newTab();
    String[] s = channels[i].split(":");
    tab.setText(s[0]);
    tab.setTag(s[1]);
    tab.setTabListener(this);

    bar.addTab(tab);
}

// Set navigation mode now, that will show all tabs in portrait mode instead of drop-down regardless the screen size
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

而已 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM