如何action_bar_embed_tabs正是在Android的工作? [英] How does action_bar_embed_tabs exactly work in Android?

查看:155
本文介绍了如何action_bar_embed_tabs正是在Android的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有卡在动作条。 在大屏幕上的选项卡嵌入到动作条,但在小屏幕上都没有。 我想控制标签说明书这样我就可以从动作条分开的选项卡。 我试图设置abs__action_bar_embed_tabs,但没有奏效。

 <资源>
    <布尔名=abs__action_bar_embed_tabs>假< /布尔>
< /资源>
 

解决方案

我知道这是旧的文章,但我想补充的使用为将来的解决方案 action_bar_embed_tabs 读者。

创建下面的方法(也照顾的进口),

 公共静态无效setHasEmbeddedTabs(对象inActionBar,最后布尔inHasEmbeddedTabs)
{
    //获取动作条类
    类<> actionBarClass = inActionBar.getClass();

    //如果它是一个果冻豆实现(ActionBarImplJB),得到了超类(ActionBarImplICS)
    如果(android.support.v7.app.ActionBarImplJB.equals(actionBarClass.getName()))
    {
            actionBarClass = actionBarClass.getSuperclass();
    }

    尝试
    {
            //尝试获得mActionBar领域,由于当前动作可能只是一个包装类
            //如果失败,不用担心,这将是本机动作条类或从ActionBarImplBase类的一个实例
            最后一个字段actionBarField = actionBarClass.getDeclaredField(mActionBar);
            actionBarField.setAccessible(真正的);
            inActionBar = actionBarField.get(inActionBar);
            actionBarClass = inActionBar.getClass();
    }
    赶上(IllegalAccessException E){}
    赶上(抛出:IllegalArgumentException E){}
    赶上(NoSuchFieldException E){}

    尝试
    {
            //现在调用该方法setHasEmbeddedTabs,这将会把标签的动作条内
            //如果失败,你在你自己的< IMG SRC =htt​​p://www.blogc.at/wp-includes/images/smilies/icon_wink.gifALT =;-)级= WP-笑脸>
            最后一个方法方法= actionBarClass.getDeclaredMethod(setHasEmbeddedTabs,新的等级[] {Boolean.TYPE});
            method.setAccessible(真正的);
            method.invoke(inActionBar,新的对象[] {inHasEmbeddedTabs});
    }
    赶上(NoSuchMethodException E){}
    赶上(的InvocationTargetException E){}
    赶上(IllegalAccessException E){}
    赶上(抛出:IllegalArgumentException E){}
}
 

然后把这个像下面,

  1. 如果您希望标签显示在操作栏里面,

    setHasEmbeddedTabs(动作条,真);

  2. 如果您希望标签出现独立/下面的操作栏,

    setHasEmbeddedTabs(动作条,假);

所有学分的悬崖。

I have tabs in an actionbar. On large screens the tabs are embed to the actionbar but on small screens the are not. I want to control the tabs manual so i can separate the tabs from the actionbar. I tried to set abs__action_bar_embed_tabs but that didn't work

<resources>
    <bool name="abs__action_bar_embed_tabs">false</bool>
</resources>

解决方案

I know this is an old post, however I would like to add a solution using action_bar_embed_tabs for future readers.

Create the below method (do take care of the imports),

public static void setHasEmbeddedTabs(Object inActionBar, final boolean inHasEmbeddedTabs)
{
    // get the ActionBar class
    Class<?> actionBarClass = inActionBar.getClass();

    // if it is a Jelly Bean implementation (ActionBarImplJB), get the super class (ActionBarImplICS)
    if ("android.support.v7.app.ActionBarImplJB".equals(actionBarClass.getName()))
    {
            actionBarClass = actionBarClass.getSuperclass();
    }

    try
    {
            // try to get the mActionBar field, because the current ActionBar is probably just a wrapper Class
            // if this fails, no worries, this will be an instance of the native ActionBar class or from the ActionBarImplBase class
            final Field actionBarField = actionBarClass.getDeclaredField("mActionBar");
            actionBarField.setAccessible(true);
            inActionBar = actionBarField.get(inActionBar);
            actionBarClass = inActionBar.getClass();
    }
    catch (IllegalAccessException e) {}
    catch (IllegalArgumentException e) {}
    catch (NoSuchFieldException e) {}

    try
    {
            // now call the method setHasEmbeddedTabs, this will put the tabs inside the ActionBar
            // if this fails, you're on you own <img src="http://www.blogc.at/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley">
            final Method method = actionBarClass.getDeclaredMethod("setHasEmbeddedTabs", new Class[] { Boolean.TYPE });
            method.setAccessible(true);
            method.invoke(inActionBar, new Object[]{ inHasEmbeddedTabs });
    }
    catch (NoSuchMethodException e)        {}
    catch (InvocationTargetException e) {}
    catch (IllegalAccessException e) {}
    catch (IllegalArgumentException e) {}
}

Then call this like below,

  1. If you want tabs to appear inside the action bar,

    setHasEmbeddedTabs(actionBar, true);

  2. If you want tabs to appear separate/ below the action bar,

    setHasEmbeddedTabs(actionBar, false);

All credits to Cliff.

这篇关于如何action_bar_embed_tabs正是在Android的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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