如何在操作栏下方显示选项卡 [英] How to display tabs below action bar

查看:33
本文介绍了如何在操作栏下方显示选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在操作栏中放置了选项卡,它工作正常.但是当我旋转设备时,它会出现在操作栏上.有什么方法可以始终在操作栏下方显示该选项卡,例如

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

这篇关于如何在操作栏下方显示选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆