bencallis
bencallis

Reputation: 3657

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.

Upvotes: 5

Views: 3168

Answers (3)

Adam Wallner
Adam Wallner

Reputation: 2412

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.

Upvotes: 3

Shafiq Mustapa
Shafiq Mustapa

Reputation: 433

I am having the same problems. I had to add these line and it is ok on AVD, don't know if it is working on real devices.

<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true" />

Upvotes: 0

Jake Wharton
Jake Wharton

Reputation: 76125

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.

Upvotes: 11

Related Questions