定位到API 26时,溢出菜单项变得不可见 [英] When targeting API 26, overflow menu items become invisible

查看:78
本文介绍了定位到API 26时,溢出菜单项变得不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个选项菜单,其中有六个以上的项目,因此有一个更多"项目可显示溢出菜单.菜单由默认菜单触发器和调用Activity.openOptionsMenu()的自定义触发器发布.

I have an options menu in my app, which has more than six items, so there is a "More" item that brings up the overflow menu. The menu is posted by the default menu triggers, and a custom trigger that invokes Activity.openOptionsMenu().

菜单本身是根据此资源文件构建的:

The menu itself is built from this resource file:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/mi_copy"
          android:title="Copy"
          android:icon="@drawable/copy"/>
    <item android:id="@+id/mi_paste"
          android:title="Paste"
          android:icon="@drawable/paste"/>
    <item android:id="@+id/mi_preferences"
          android:title="Preferences"
          android:icon="@android:drawable/ic_menu_preferences"/>
    <item android:id="@+id/mi_flip_calc_printout"
          android:title="Print-Out"
          android:icon="@drawable/printer"/>
    <item android:id="@+id/mi_clear_printout"
          android:title="Clear Print-Out"
          android:icon="@android:drawable/ic_menu_close_clear_cancel"/>
    <item android:id="@+id/mi_about"
          android:title="About Free42"/>
    <item android:id="@+id/mi_import"
          android:title="Import Programs"/>
    <item android:id="@+id/mi_export"
          android:title="Export Programs"/>
</menu>

到目前为止,太好了.菜单和创建并发布菜单的Java逻辑已经使用了多年,但是现在,根据最新的Play要求,我将targetSdkVersion从API级别8更改为26,现在突然之间,菜单项溢出了菜单变得不可见.

So far, so good. The menu and the Java logic that creates and posts it has worked for years, but now I'm changing the targetSdkVersion from API level 8 to 26, per the latest Play requirements, and now all of a sudden, the menu items in the overflow menu have become invisible.

溢出菜单仍然会发布,并且大小仍然正确,并且菜单项仍然有效.您只是再也看不到它们了:整个菜单现在是纯黑色,这是正常的背景色;菜单项文本丢失.

The overflow menu still posts, and it still has the correct size, and the menu items still work. You just can't see them any more: the whole menu is solid black now, which is the normal background color; the menu item text is missing.

我正在测试的手机是运行Android 8.1.0的Motorola G5.这是我目前唯一可以使用API​​ 26进行测试的设备,至少直到我弄清楚如何使用API​​> = 26创建AVD为止.

The phone on which I'm testing is a Motorola G5 running Android 8.1.0. This is the only device I have available for testing with API 26 at the moment, at least until I figure out how to create an AVD with API >= 26.

在具有API级别8图像的Android模拟器中,溢出菜单仍然看起来不错.在我定位到API 26之前,它在Moto G5上也看起来还不错.如果我将目标改回8,则溢出菜单将再次起作用.

N.B. In the Android simulator with an API level 8 image, the overflow menu still looks fine. It used to look fine on the Moto G5 as well, before I targeted API 26. If I change the target back to 8, the overflow menu works again.

对我可以解决此问题有何想法?我的Google技能在这方面不起作用...任何想法都将受到欢迎!

Any thoughts on what I could do to fix this? My Google skills aren't working on this one... Any ideas would be most welcome!

推荐答案

我将此样式文件添加为res/values/styles.xml:

I added this style file as res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Free42Theme" parent="android:style/Theme.NoTitleBar">
        <item name="android:itemBackground">@android:color/white</item>
    </style>

    <style name="Free42Theme.Fullscreen" parent="android:style/Theme.NoTitleBar.Fullscreen">
        <item name="android:itemBackground">@android:color/white</item>
    </style>

</resources>

第一个是默认主题,通过将Activity上的android:theme属性从AndroidManifest.xml中的@android:style/Theme.NoTitleBar更改为@ style/Free42Theme来指定;第二个是通过将setTheme(android.R.style.Theme_NoTitleBar_Fullscreen)调用更改为setTheme(R.style.Free42Theme_Fullscreen),在Java代码中设置的全屏主题.

The first is the default theme, specified by changing the android:theme attribute on the Activity from @android:style/Theme.NoTitleBar to @style/Free42Theme in AndroidManifest.xml; the second is the full-screen theme, set in the Java code, by changing the setTheme(android.R.style.Theme_NoTitleBar_Fullscreen) call to setTheme(R.style.Free42Theme_Fullscreen).

这会将溢出菜单的背景更改为白色,从而使黑色项目文​​本可见,并在我的G5上进行了验证.在具有Android 2.2(API级别8)的模拟器中运行,外观从一开始就是白色的,因此外观没有变化.

This changes the background of the overflow menu to white, making the black item text visible, verified on my G5. Running in the simulator with Android 2.2 (API level 8), the appearance is unchanged since the background was white there from the start.

非常感谢SteelToe让我走上正轨!

Many thanks to SteelToe for getting me on the right track!

这篇关于定位到API 26时,溢出菜单项变得不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆