Forcibly display Actionbar and Tab as one or two rows, actionbartab
Actionbar uses the Tab Mode
- ActionBar. setNavigationMode (ActionBar. NAVIGATION_MODE_TABS) can be used as the navigation mode for another Actionbra;
- ActionBar. addTab (Tab tab) use this method to add a specific Tab for your navigation;
Is it a single row or two rows?
- According to the Developer's official Holo Design Guide, when the screen width is sufficient, the Tab will be embedded into the Actionbar and displayed as a line, such as when the screen Pad or mobile phone is landscape;
- When the screen width is narrow, the Tab is displayed in the next line of the Actionbar, a total of two lines, common in mobile phone portrait;
Forcibly display as one or two rows in all cases
- Sometimes the dual-line Tab needs to be displayed on the pad, or the single-line Actionbar needs to be displayed in the portrait screen of the mobile phone;
Forcibly display as a single row
try { Method setHasEmbeddedTabsMethod = mActionBar.getClass().getDeclaredMethod( "setHasEmbeddedTabs", boolean.class); setHasEmbeddedTabsMethod.setAccessible(true); setHasEmbeddedTabsMethod.invoke(mActionBar, true); } catch (Exception ignore) { }
Forcibly display as two rows
try { Method setHasEmbeddedTabsMethod = mActionBar.getClass().getDeclaredMethod( "setHasEmbeddedTabs", boolean.class); setHasEmbeddedTabsMethod.setAccessible(true); setHasEmbeddedTabsMethod.invoke(mActionBar, false); } catch (Exception ignore) { }
Use ActionbarSherlock
- ActionbarSherlock directly calls Android native Actionbar in Android 3.0 and later versions, and uses built-in Actionbar for compatibility in Android 2.3 and later versions;
- In the native class ActionBarWrapper, modify private final android. app. ActionBar mActionBar through reflection above;
- In the compatible ActionBarImpl class, specify the parameter in setHasEmbeddedTabs (boolean hasEmbeddedTabs;