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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();
}
}