简体   繁体   English

为什么棒棒糖上的操作栏的android下拉菜单看起来不同?

[英]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. 经过几个月的开发,我现在正在开发一个Android应用程序,现在陷入了一个愚蠢的问题。

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. 我基本上遇到的问题是下拉菜单(来自操作栏),该菜单根据我的styles.xml看起来像白色背景上方的深色文本。 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. 但是在不同的设备上测试我的应用程序时,我注意到在Lollipop上,相同的下拉菜单在深色背景上显示深色文本,因此这种文本几乎无法读取。

I thought that "issue" was related to the folders "values-v11" and "values-v14" and their respective styles.xml under raw directory. 我认为“问题”与原始目录下的文件夹“ values-v11”和“ values-v14”及其各自的styles.xml有关。 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. 尝试播放此文件,以复制我在styles.xml主要文件中设置的部分或全部设置,但没有结果。

This is how my styles.xml file looks like: 这是我的styles.xml文件的样子:

<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 <item name="android:popupMenuStyle">有两个冲突的定义<item name="android:popupMenuStyle"> “ AppTheme”内部有一个@android:style/Widget.Holo.PopupMenu Widget.Holo.PopupMenu“ 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". 棒棒糖设备正在“ AppTheme”下找到一台设备,问题已经解决了,方法是将其删除,然后将其留在“ MyActionBarWidget”下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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