Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force stacked tabs

Is there any way to force stacked tabs? I want tabs separate of action bar (in a second row), even when landscape mode.

I am trying to force it but I can´t. For example, Twitter app in Android, when change to lanscape mode, continue showing two rows (tabs in a separate rows, which are known as stacked tabs).

Thanks!

like image 423
LopezAgrela Avatar asked Nov 19 '12 18:11

LopezAgrela


People also ask

How to enable stacked tabs in Google Chrome?

1 First of all type chrome://flags/ in Google Chrome addressbar and press Enter. It'll open advanced configuration page. 2 Press " Ctrl+F " keys together to launch find box and type following in the find box: Stacked Tabs It'll highlight an option with the same name. ... 3 Click on the " Enable " link given below the option. More items...

What is tab stacking and how does it work?

They shrink the tabs to a pre-defined size and once they reach that size limit, they start stacking new tabs to the right and small arrow icons are shown on the tab bar to navigate between tabs. It helps in easily switching between running tabs.

How to create and manage tab stacks in Windows 10?

Click and start dragging one tab over another or over an existing Tab Stack; When the second tab is dimmed, release the mouse button. You can adjust Stacking Drop Delay in Settings > Tabs > Tab Features > Tab Stack Options. Make it longer, if you often accidentally create Tab Stacks, when dragging tabs from one place on the Tab Bar to another.

What happens when the tab stack is expanded or collapsed?

When the Tab Stack is expanded, the tabs in the stack will share the available space on the Tab Bar with all other tabs. The stack will expand automatically when viewing a tab in the stack and collapse, when viewing other tabs. To keep the Tab Stack open, click on the Expand/Reduce Tab Stack button or double click on the collapsed Tab Stack.


2 Answers

Not only can you not force stacked tabs, you can't even force tabs -- Android can and will replace them with a drop-down list for navigation in some screen sizes and orientations.

Your only solution is to move away from action bar tabs, such as by using ViewPager and PagerTabStrip.

like image 184
CommonsWare Avatar answered Oct 11 '22 15:10

CommonsWare


I had luck using the following reflection 'hack':

private void forceStackedTabs() {
    ActionBar ab = getSupportActionBar();
    if ( ab instanceof ActionBarImpl ) {
        // Pre-ICS
        disableEmbeddedTabs( ab );
    } else if ( ab instanceof ActionBarWrapper ) {
        // ICS
        try {
            Field abField = ab.getClass().getDeclaredField( "mActionBar" );
            abField.setAccessible( true );
            disableEmbeddedTabs( abField.get( ab ) );
        } catch (NoSuchFieldException e) {
            Log.e( TAG, "Error disabling actionbar embedded", e );
        } catch (IllegalArgumentException e) {
            Log.e( TAG, "Error disabling actionbar embedded", e );
        } catch (IllegalAccessException e) {
            Log.e( TAG, "Error disabling actionbar embedded", e );
        }
    }
}
private void disableEmbeddedTabs(Object ab) {
    try {
        Method setHasEmbeddedTabsMethod = ab.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(ab, false);
    } catch (Exception e) {
        Log.e( TAG, "Error disabling actionbar embedded", e );
    }
}

Please note that I didn't think of this myself, but simply rewrote the code given in this answer: replicate ActionBar Tab(s) with custom view

like image 38
JesperB Avatar answered Oct 11 '22 16:10

JesperB