Created
December 3, 2013 03:29
-
-
Save PrashamTrivedi/7763439 to your computer and use it in GitHub Desktop.
android : Embed tabs as a part of actionbar.... as done in shazaam apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In onCreate after initializing actionbar | |
int currentapiVersion = android.os.Build.VERSION.SDK_INT; | |
if (currentapiVersion >= VERSION_CODES.ICE_CREAM_SANDWICH) { | |
// Do something for froyo and above versions | |
try { | |
Field actionBarField = actionBar.getClass().getDeclaredField("mActionBar"); | |
actionBarField.setAccessible(true); | |
enableEmbeddedTabs(actionBarField.get(actionBar)); | |
} catch (Exception e) { | |
Log.e(TAG, "Error enabling embedded tabs", e); | |
} | |
} else { | |
// do something for phones running an SDK before froyo | |
enableEmbeddedTabs(actionBar); | |
} | |
//code for enableEmbeddedTabs | |
private void enableEmbeddedTabs(Object actionBar) { | |
try { | |
Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class); | |
setHasEmbeddedTabsMethod.setAccessible(true); | |
setHasEmbeddedTabsMethod.invoke(actionBar, true); | |
} catch (Exception e) { | |
Log.e(TAG, "Error marking actionbar embedded", e); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment