How to display tabs below action bar

前端 未结 1 451
梦谈多话
梦谈多话 2021-01-15 19:17

I have placed tabs in action bar and it is working fine. but when i rotate device it will appear on the action bar. Is there any way to always display that tab below action

相关标签:
1条回答
  • 2021-01-15 19:34

    Used the following function which force to show stacked tabs

    private void forceStackedTabs(ActionBar ab)
        {
            try
            {
                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 (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
    private void disableEmbeddedTabs(Object ab)
        {
            try
            {
                Method setHasEmbeddedTabsMethod = ab.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
                setHasEmbeddedTabsMethod.setAccessible(true);
                setHasEmbeddedTabsMethod.invoke(ab, false);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
    0 讨论(0)
提交回复
热议问题