listView上的弹出菜单项不可见

时间:2016-10-25 12:06:29

标签: android android-layout menu menuitem popupmenu

我在ListView上使用图像按钮,单击时会显示一个弹出菜单。 但问题是物品不可见。 这就是菜单的样子。我可以在这张图片的菜单上看到白色文字,但在移动屏幕上它是不可见的。 enter image description here

这是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>

这是Quiz Fragment的布局文件。

<?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>

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

<?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>

我尝试了之前提出的许多解决方案(都是关于工具栏菜单),但没有一个对我有用。 我在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>

并将其包含在没有工作的AppTheme中。然后我将其包含在工具栏样式,菜单布局,QuizFragment布局中,但项目仍然不可见。如何更改菜单的背景颜色或项目颜色来修复此问题,任何人都会工作。

2 个答案:

答案 0 :(得分:1)

试试这个

style.xml

function parseDMY(s) {
  var b = s.split(/\D/);
  var d = new Date(b[2], --b[1], b[0]);
  // If month is wrong, return invalid date
  return d && d.getMonth() == b[1]? d : new Date(NaN);
}

// Dates in d/m/y format
['23/10/2015','32/10/2015','12/13/2015'].forEach(function(s){
  var d = parseDMY(s);
  console.log(s + ' : ' + (isNaN(d)? 'Invalid' : 'Valid'));
});

并在<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>

中定义Activity的主题
AndroidManifest.xml

答案 1 :(得分:0)

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

Theme.MaterialComponents.DayNight.NoActionBar.Bridge

在它们里面,我只有白天和黑夜的同名物品,但颜色不同。发现(经过实验)...在我的情况下(与您的问题相同),此行改变了游戏规则,标题和菜单为白色,同时弹出菜单上的文本为黑色

        <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>

仅此而已,

快乐编码, 内纳德