Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionbarSherlock - tabs unresponsive in landscape orientation

I am currently backporting my application to make it work on device prior to 3.0 using actionbarsherlock.

If a user launches the application in portrait mode and then rotates the screen and tries to select a tab nothing happens until the user preforms another action. The current build which does this can be downloaded here (sherlock-alpha1) http://tinyurl.com/cz95nup.

Tabs are added in the following way

        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.addTab(bar.newTab().setText("tab1").setTabListener(this),false);
        bar.addTab(bar.newTab().setText("tab2").setTabListener(this),false);
        bar.addTab(bar.newTab().setText("tab3").setTabListener(this),false);

This also occurs if you launch the application in landscape and then use it in portrait mode (portrait tabs will not work).

It is working fine on devices running the native actionbar.

like image 400
bencallis Avatar asked Apr 07 '12 14:04

bencallis


2 Answers

Are you handling configuration changes in the manifest?

android:configChanges="orientation"

If so this is not allowing the fake decor view that ActionBarSherlock installs to be re-initialized on rotation which will cause many problems.

Handling configuration changes should be used as sparingly as possible. The documentation states that it should be used as a last resort.

Future versions of the library will hopefully be able to account for people who choose to do this.

like image 191
Jake Wharton Avatar answered Oct 24 '22 00:10

Jake Wharton


For me it was unresponsive after orientation changes, not in landscape mode. After a lot of trial and errors I've found the following solution for this bug:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    super.onConfigurationChanged(newConfig);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}

The trick is to change the navigation mode to list then change back to tabs.

like image 35
Adam Wallner Avatar answered Oct 23 '22 23:10

Adam Wallner