Skip to content

Instantly share code, notes, and snippets.

@PrashamTrivedi
Created December 3, 2013 03:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrashamTrivedi/7763439 to your computer and use it in GitHub Desktop.
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
//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