简体   繁体   中英

Why does android dropdown menu of action bar look different on Lollipop?

I am building an android app, after months of developing I now got stuck in what it seems to be a silly problem.

The problem I have basically is with the dropdown menu (coming from the action bar) which looks according to my styles.xml with a dark text above a white backgroud. However testing my application on different devices, I have noticed that on Lollipop the same dropdown menu looks dark text on dark background making this way the text almost impossible to be read.

I thought that "issue" was related to the folders "values-v11" and "values-v14" and their respective styles.xml under raw directory. Tried to play a bit with this files copying some or all of the settings I have in the main styles.xml but got no result.

This is how my styles.xml file looks like:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabStyle">@style/MyActionBar.Tab</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBar.TabBar</item>
    <item name="android:icon">@android:color/transparent</item> 
    <item name="android:homeAsUpIndicator">@drawable/ic_back_arrow</item>
    <item name="android:popupMenuStyle">@android:style/Widget.Holo.PopupMenu</item>
    <item name="android:actionBarWidgetTheme">@style/MyActionBarWidget</item>
    <item name="android:dropDownListViewStyle">@android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>

<style name="MyActionBarWidget" parent="android:Theme.Holo.Light">
    <item name="android:popupMenuStyle">@android:style/Widget.Holo.Light.PopupMenu</item>
    <item name="android:dropDownListViewStyle">@android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@color/actionbar_background</item>
    <item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
    <item name="android:subtitleTextStyle">@style/Theme.MyAppTheme.ActionBar.SubTitleTextStyle</item>
</style>

<style name="MyActionBar.Tab">
    <item name="android:background">@drawable/tab_bar_background</item>
    <item name="android:gravity">center</item>
</style>    

<style name="MyActionBar.TabBar">
    <item name="android:background">@color/actionbar_background</item>
</style>

<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
</style>

<style name="Theme.MyAppTheme.ActionBar.SubTitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
    <item name="android:textColor">@color/white</item>
</style>

After "refreshing my mind" on holidays for a couple of weeks, once back realised what was creating the issue:

There are two conflicting definitions for <item name="android:popupMenuStyle"> One inside "AppTheme" @android:style/Widget.Holo.PopupMenu One inside "MyActionBarWidget" @android:style/Widget.Holo.Light.PopupMenu

Lollipop devices were picking up the one under "AppTheme", problem has been sorted by getting rid of it and leaving the one under "MyActionBarWidget".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM