如何显示在下面操作栏标签操作、标签

2023-09-12 01:58:47 作者:砸中牛顿的土豪金

我把卡在操作栏,这是工作的罚款。但是当我旋转设备就会出现在操作栏。有没有什么办法,始终显示在下面的动作条,标签如

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 bar like

推荐答案

用于以下功能,强制显示堆叠标签

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();
        }
    }