Android 更改弹出菜单上的文本颜色

标签 android popupmenu textcolor

在我的应用程序中,当我单击三点按钮时,菜单项会在白色背景上以白色文本颜色显示。我想将文本颜色更改为黑色,但它不起作用。我一直在寻找解决方案,但没有一个有效。 这是我的代码:

样式.xml

<resources>
<style name="AppMaterialTheme" parent="SuperMaterialTheme">

</style>


<!-- Base application theme. -->
<style name="SuperMaterialTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_background</item>

</style>


<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>

</style>



<style name="PopupTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorPrimary">#000000</item>

</style>

工具栏.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
app:popupTheme="@style/PopupTheme"
>

哪里错了?提前致谢

最佳答案

您要求的菜单称为溢出菜单。您可以通过在 style.xml 中添加新样式来更改溢出菜单背景的颜色。

  <style name="OverflowMenu"
  parent="@android:style/Theme.Holo">
  <item name="android:popupMenuStyle">@style/MyOverflowMenu</item>
  <item name="android:itemTextAppearance">@style/TextAppearance</item>
  </style>
  <style name="MyOverflowMenu" 
  parent="@android:style/Widget.Holo.ListPopupWindow">
  <item name="android:popupBackground">@color/your_color</item> 
  </style>
  <style name="TextAppearance">
  <item name="android:textColor">@color/your_color</item>
  </style>

关于Android 更改弹出菜单上的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45397714/

相关文章:

android - .apk 签名即使使用 Sun JDK 也会失败(java.lang.NoClassDefFoundError : com. android.jarutils.DebugKeyProvider)

Delphi:弹出菜单

Android 将 textColor 值设置为全局

swift - 如何在 subview 中保留控制文本颜色的功能?

android - EditText无法更改文字颜色

Android OnClickListener 没有在第一次点击时触发

Android自定义形状按钮或imageview点击区域

android - 使用 ktor 进行流式下载

javascript - 我应该监听哪些事件以在 JavaScript 中隐藏自定义上下文菜单

android - 在android中为弹出菜单的选定项目添加刻度线