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
Asked
Active
Viewed 985 times
2

Nikhil
- 2,857
- 9
- 34
- 58
1 Answers
2
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();
}
}

Sandeep
- 1,814
- 21
- 25
-
I commented the if-else if because I don't konw what you meant by ActionBarImpl and ActionBarWrapper and it works. Thanks! (If you want to explain that to me that'd be awesome :D) – RominaV Mar 26 '14 at 12:58
-
Hey I have place a comment regarding same. Before ICS 4.0 ActionBar was instance of ActionBarImpl class and from ICS it is instance of ActionBarWrapper class. Test this functionality on different OS. – Sandeep Mar 26 '14 at 14:24
-
THANK YOU! Your code works well for me. Additional note: I think the ActionBarWrapper applies only if you use ActionBarSherlock library. In my case, I don't and android default implementation is its internal ActionBarImpl class. – Panini Luncher Jun 04 '14 at 19:23
-
@Sandy - I tried to use this. But I am getting exception like java.lang.NoSuchFieldException: mActionBar In my code, ActionBar variable is being declared as _actionBar. So, I changed the line Field abField = ab.getClass().getDeclaredField("mActionBar"); as Field abField = ab.getClass().getDeclaredField("_actionBar"); But still, I am getting the similar exception. Any idea on this? – Kameswari Jun 24 '14 at 12:12
-
Can you help me with the ActionBar i.e used of supportlibrary v7. I am getting no such method error. – BSKANIA Sep 25 '14 at 07:27