Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Preserve tab behavior onOrientationChange (issue #365) #549

Closed
wants to merge 1 commit into from

5 participants

@yigit

This commit fixes tab behavior bug onOrientationChange when Activity handles orientation changes (android:configChanges="orientation").

Probably, this is not the proper implementation because it re-creates tab layout but for our case, it solves the problem.
Tested on Android 2.3.4 and Android 4.0.4.

@buildhive

Jake Wharton » ActionBarSherlock #27 SUCCESS
This pull request looks good
(what's this?)

@Unlogic-dot-se

I've tested these changes and they indeed solve the problem with tab rotation when the Activity is configured using android:configChanges="orientation|keyboardHidden" in the manifest.

@SimonVT
Collaborator

Tabs aren't the only thing affected by runtime changes, which is why this won't be merged. That, and handling runtime changes is horrible.

@Unlogic-dot-se

Okay, I understand that the fix may have side effects and cannot be merged. The bug however is valid and causes tabs to become unresponsive when orientation changes on Android 2.x (haven't tested 3.x).

The native ActionBar tabs on Android 4.x handles the rotation just fine when android:configChanges="orientation|keyboardHidden" is set on the activity.

Edit: Ignore this comment, I found Jake's reply on the bug here #279

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 12, 2012
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 0 deletions.
  1. +20 −0 library/src/com/actionbarsherlock/internal/app/ActionBarImpl.java
View
20 library/src/com/actionbarsherlock/internal/app/ActionBarImpl.java
@@ -187,6 +187,7 @@ public void onConfigurationChanged(Configuration newConfig) {
mContextView.onConfigurationChanged(newConfig);
}
}
+ recreateTabs();
}
private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
@@ -340,6 +341,25 @@ private void cleanupTabs() {
mSavedTabPosition = INVALID_POSITION;
}
+ private void recreateTabs() {
+ if(mTabScrollView == null) {
+ return;
+ }
+ ArrayList<TabImpl> tabs = new ArrayList<TabImpl>(mTabs);
+ int tabPosition = getSelectedNavigationIndex();
+ cleanupTabs();
+ mTabScrollView.onDetachedFromWindow();
+ mTabScrollView = null;
+ ensureTabsExist();
+ for(ActionBar.Tab tab : tabs) {
+ addTab(tab, false);
+ }
+ if(tabPosition != INVALID_POSITION) {
+ selectTab(tabs.get(tabPosition));
+ }
+
+ }
+
public void setTitle(CharSequence title) {
mActionView.setTitle(title);
}
Something went wrong with that request. Please try again.