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,
If you want tabs to appear inside the action bar,
setHasEmbeddedTabs(actionBar, true);
If you want tabs to appear separate/ below the action bar,
setHasEmbeddedTabs(actionBar, false);
All credits to Cliff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With