问题描述:

Some users of my application are experiencing a weird problem when using my application in landscape mode. I am using actionbarsherlock and have set the navigation mode to tabs (using ActionBar.NAVIGATION_MODE_TABS).

Some users are finding when launching the app in portrait and then rotating the device the actionbar shows a spinner list rather than the tabs (which apparently is expected behaviour). The problem is the spinner is not selectable.

 bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

bar.addTab(bar.newTab().setText("Deals").setTabListener(this),false);

bar.addTab(bar.newTab().setText("Vouchers").setTabListener(this),false);

bar.addTab(bar.newTab().setText("Freebies").setTabListener(this),false);

EDIT

Just discovered it is related to my custom theme. Changing the theme to the default Sherlock.Light makes the spinner selectable. The custom theme is shown below.

<!-- Variation on the Holo Light theme that styles the Action Bar -->

<style name="DealPadTheme" parent="Theme.Sherlock.Light.ForceOverflow">

<item name="android:selectableItemBackground">@drawable/ad_selectable_background</item>

<item name="actionBarItemBackground">@drawable/ad_selectable_background</item>

<item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>

<item name="actionBarTabStyle">@style/MyActionBarTabStyle</item>

<item name="android:actionBarStyle">@style/Widget.ActionBar</item>

<item name="actionBarStyle">@style/Widget.ActionBar</item>

<item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>

<item name="dropDownListViewStyle">@style/MyDropDownListView</item>

<item name="android:actionDropDownStyle">@style/MySpinner</item>

<item name="actionDropDownStyle">@style/MySpinner</item>

<item name="android:activatedBackgroundIndicator">@drawable/selectable_list_item</item>

<item name="activatedBackgroundIndicator">@drawable/selectable_list_item</item>

<item name="android:listSelector">@style/MyListView</item>

</style>

<style name="MyListView" parent="@android:style/Widget.ListView">

<item name="android:listSelector">@drawable/list_arrow_selected_holo</item>

</style>

<!-- style for the tabs -->

<style name="MyActionBarTabStyle">

<item name="android:background">@drawable/actionbar_tab_bg</item>

<item name="android:paddingLeft">16dp</item>

<item name="android:paddingRight">16dp</item>

<item name="android:gravity">center_horizontal</item>

</style>

<style name="Widget.ActionBar" parent="Widget.Sherlock.Light.ActionBar">

<item name="android:displayOptions">showHome|useLogo|showCustom</item>

<!-- removed as not all activites need it <item name="android:customNavigationLayout">@layout/custom_action_bar</item> -->

<item name="android:background">@drawable/ad_tab_unselected_holo</item>

<item name="background">@drawable/ad_tab_unselected_holo</item>

<item name="android:titleTextStyle">@style/Widget.ActionBar.Title</item>

<item name="titleTextStyle">@style/Widget.ActionBar.Title</item>

</style>

<style name="Widget.ActionBar.Title" parent="Widget">

<item name="android:textSize">12sp</item>

<item name="android:textStyle">bold</item>

<item name="android:textColor">?android:attr/textColorPrimary</item>

</style>

<!-- style the items within the overflow menu -->

<style name="MyDropDownListView" parent="Widget.Sherlock.Light.ListView.DropDown">

<item name="android:listSelector">@drawable/ad_selectable_background</item>

</style>

<!-- style the items within the overflow menu -->

<style name="MySpinner">

<item name="android:background">@drawable/spinner_background</item>

</style>

网友答案:

Wow so it turns out it was as I hadn't stated the parent when themeing ActionDropDownStyle.

It's only when I created a new project was that I discovered it was related to the theme.I presumed it was an issue relating to the code or handling orientation change incorrectly.

Doing the following sorts it:

<!-- style the items within the overflow menu -->
<style name="MySpinner" parent="Widget.Sherlock.Light.Spinner.DropDown.ActionBar" >
    <item name="android:background">@drawable/spinner_background</item>
</style>

The only issue now is some of the spinner items are cut off and replaced with ... Although I think this is a known bug.

相关阅读:
Top