listView 上的弹出菜单项不可见

popup menu items on listView are not visible

我在 ListView 上使用图像按钮,单击它会显示弹出菜单。 但问题是项目不可见。 这就是 menu looks.I 可以在这张图片中看到菜单上的白色文本,但在移动屏幕上它是不可见的。

这是styles.xml

<resources>
    <!-- Base application theme. -->
   <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

       <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorBackground">@color/colorPrimary</item>
        <item name="android:textColorPrimary">@android:color/black</item>
        <item name="android:textColorSecondary">#fcfcfc</item>
        <item name="android:actionMenuTextColor">@color/black</item>
   </style>

    <style name="itemTextStyle.AppTheme" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:colorBackground">@color/colorPrimary</item>

    </style>

    <!-- LoginCreateText -->
    <style name="LoginCreateText">
        <item name="android:textSize">@dimen/login_buttons_text_size</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:layout_margin">2dp</item>
    </style>

    <!-- LoginCreateTextButton -->
    <style name="LoginCreateTextButton">
        <item name="android:textSize">@dimen/login_buttons_text_size</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="android:layout_margin">2dp</item>
        <item name="android:clickable">true</item>
    </style>

    <style name="HintText">
        <item name="android:textSize">0dp</item>
    </style>

    <style name="FAB">
        <item name="android:layout_margin">0dp</item>
        <item name="fabSize">normal</item>
        <item name="rippleColor">@android:color/white</item>
        <item name="backgroundTint">@color/colorAccent</item>
    </style>

    <style name="ListItemText">
        <item name="android:textColor">@color/light_black</item>
        <item name="android:textSize">@dimen/list_item_text_size</item>
        <item name="android:layout_margin">2dp</item>
    </style>
</resources>

这是themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Widget.Button.Login" parent="android:Widget.Button">
        <item name="android:paddingLeft">18dp</item>
        <item name="android:paddingRight">16dp</item>
        <item name="android:textSize">@dimen/login_buttons_text_size</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:background">@color/colorPrimary</item>
    </style>

    <style name="Toolbar" parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:itemTextAppearance">@style/itemTextStyle.AppTheme</item>
        <item name="android:background">@color/colorPrimary</item>
        <item name="android:textColorPrimary">@android:color/white</item>
    </style>
    <style name="CustomTheme.Dialog" parent="Theme.AppCompat.Light.Dialog"/>
</resources>

这是我要显示的菜单。

   <?xml version="1.0" encoding="utf-8"?>
         <menu xmlns:app="http://schemas.android.com/apk/res-auto"
         xmlns:android="http://schemas.android.com/apk/res/android"
         app:popupTheme="@style/itemTextStyle.AppTheme">

<item
android:id="@+id/action_edit"
android:title="@string/action_edit" />

<item
    android:id="@+id/action_delete"
    android:title="@string/action_delete"/>

<item
    android:id="@+id/action_assign"
    android:title="@string/action_assign"
    android:checkable="true"/>

<item
    android:id="@+id/action_mark"
    android:title="@string/action_mark"
    android:enabled="false"/>
</menu>

这是测验片段的布局文件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl_fragment_quiz_lists"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey"
    app:popupTheme="@style/itemTextStyle.AppTheme"
    tools:context=".ui.fragments.QuizFragment">

    <include layout="@layout/single_active_list" />

    <ListView
        android:id="@+id/list_view_active_lists"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none" />

    <android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        style="@style/FAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:onClick="showAddQuizDialog"
        android:src="@drawable/ic_add_quiz"
        app:borderWidth="0dp"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp">
        <!--app:rippleColor="@android:color/white" /> -->
    </android.support.design.widget.FloatingActionButton>

</RelativeLayout>

这是显示此片段的 activity 的布局文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/Toolbar" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Toolbar" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

我已经尝试了很多以前被问到的解决方案(都是关于工具栏菜单的)但是 none 对我有用。 我在 styles.xml

中定义了一个新样式
<style name="itemTextStyle.AppTheme" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:colorBackground">@color/colorPrimary</item>

并将其包含在没有 work.then 的 AppTheme 中要解决这个问题,任何一个都可以。

试试这个

style.xml

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat">
    <item name="android:actionOverflowButtonStyle">@style/OverflowButton</item>
    <item name="actionOverflowButtonStyle">@style/OverflowButton</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>
    <item name="dropDownListViewStyle">@style/PopupMenuListView</item>
    <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
    <item name="actionBarDivider">@null</item>
    <!-- OverFlow Menu Text Color -->
    <item name="android:textColor">@color/black</item>
</style>

<!-- OverFlow menu Styles -->
<style name="PopupMenuListView" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
    <item name="android:divider">@color/black</item>
    <item name="android:dividerHeight">1dp</item>
    <item name="android:background">@color/white</item>
</style>

<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
    <!-- Required for pre-Lollipop. -->
    <item name="overlapAnchor">false</item>
    <!-- Required for Lollipop. -->
    <item name="android:overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">4.0dip</item>
</style>

并在 AndroidManifest.xml

中为 Activity 定义主题
<activity
 android:name=".YourActivityName"
 android:theme="@style/CustomActionBarTheme"/>

我只使用了两个主题文件(黑暗和白天)

Theme.MaterialComponents.DayNight.NoActionBar.Bridge

在它们里面,我只有白天和黑夜的同名物品,但颜色不同。发现(经过实验)...在我的情况下,这一行是 game-changer(与您的问题相同),标题和菜单为白色,而同时弹出菜单上的文本为黑色

        <item name="android:textColorSecondary">@android:color/white</item>

这是整个文件,我只使用了这个,并尽量不对任何内容进行硬编码。

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Ch+++itche+++++" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
    <!-- Primary brand color. -->

    <item name="android:textColorSecondary">@android:color/white</item>
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryVariant">@color/primaryDarkColor</item>
    <item name="colorOnPrimary">@color/primaryLightColor</item>
    <item name="colorOnSurface">@color/primaryColorWhiteDay</item>
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
</style>

就是这样,

编码愉快, 内纳德