Skip to content
This repository

Preserve tab behavior onOrientationChange (issue #365) #549

Closed
wants to merge 1 commit into from

5 participants

Yigit Boyar BuildHive Unlogic-dot-se Simon Vig Therkildsen Jake Wharton
Yigit Boyar
yigit commented

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?)

Jake Wharton JakeWharton closed 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.

Simon Vig Therkildsen
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

Showing 1 unique commit by 1 author.

Jul 12, 2012
Yigit Boyar fixes tab functionality problem onOrientationChange 5c0d48d
This page is out of date. Refresh to see the latest.
20  library/src/com/actionbarsherlock/internal/app/ActionBarImpl.java
@@ -187,6 +187,7 @@ public void onConfigurationChanged(Configuration newConfig) {
187 187
                 mContextView.onConfigurationChanged(newConfig);
188 188
             }
189 189
         }
  190
+        recreateTabs();
190 191
     }
191 192
 
192 193
     private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
@@ -340,6 +341,25 @@ private void cleanupTabs() {
340 341
         mSavedTabPosition = INVALID_POSITION;
341 342
     }
342 343
 
  344
+    private void recreateTabs() {
  345
+        if(mTabScrollView == null) {
  346
+            return;
  347
+        }
  348
+        ArrayList<TabImpl> tabs = new ArrayList<TabImpl>(mTabs);
  349
+        int tabPosition = getSelectedNavigationIndex();
  350
+        cleanupTabs();
  351
+        mTabScrollView.onDetachedFromWindow();
  352
+        mTabScrollView = null;
  353
+        ensureTabsExist();
  354
+        for(ActionBar.Tab tab : tabs) {
  355
+            addTab(tab, false);
  356
+        }
  357
+        if(tabPosition != INVALID_POSITION) {
  358
+            selectTab(tabs.get(tabPosition));
  359
+        }
  360
+
  361
+    }
  362
+
343 363
     public void setTitle(CharSequence title) {
344 364
         mActionView.setTitle(title);
345 365
     }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.