简体   繁体   English

Android更改弹出菜单文本颜色

[英]Android change popup menu text color

I've tried many things to change the text color when i click the "three dot" menu button but it always reverts back to the toolbar (android:theme) theme and not the android:popupTheme. 当我单击“三个点”菜单按钮时,我已经尝试了很多方法来更改文本颜色,但是它总是恢复为工具栏(android:theme)主题,而不是android:popupTheme。 I want the text to be black but it always shows up white. 我希望文本为黑色,但始终显示为白色。

styles.xml styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
</style>
<style name="MaterialWorkout_theme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorPrimary">#FFFFFF</item>
    <item name="android:textColorSecondary">#48FFFFFF</item>
</style>
<style name="Popup_theme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorPrimary">#000000</item>
    <item name="android:textColorSecondary">#38000000</item>
</style>

app_bar.xml app_bar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
android:id="@+id/app_bar"
android:theme="@style/MaterialWorkout_theme"
android:popupTheme="@style/Popup_theme"
>

Here is what it looks like: http://imgur.com/svRuuHK 外观如下: http : //imgur.com/svRuuHK

Solved it. 解决了。 changed my toolbar.xml file to this: 将我的toolbar.xml文件更改为:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/primaryColor"
android:id="@+id/tool_bar"
android:theme="@style/MaterialWorkout_theme"
app:popupTheme="@style/Popup_theme">

notice the implementation of: 注意以下实现:

xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app =“ http://schemas.android.com/apk/res-auto”

and

app:popupTheme="@style/Popup_theme" app:popupTheme =“ @ style / Popup_theme”

these two lines solved my problem! 这两行解决了我的问题!

You need to define your popup menu theme in your style, not you Toolbar. 您需要以样式而不是工具栏定义弹出菜单主题。

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
    <item name="popupMenuStyle">@style/Popup_theme</item>
</style>

Use below code .I hope this will solve your problem.You can change both background color and textcolor. 使用下面的代码。我希望这可以解决您的问题。您可以更改背景颜色和文本颜色。

 <style name="AppFullScreenThemeNight" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
    <!-- if using android.support.v7.widget.PopupMenu -->
    <item name="popupMenuStyle">@style/PopupMenu</item>
    <item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>


<style name="PopupMenu" parent="ThemeOverlay.AppCompat.ActionBar">
    <item name="android:popupBackground">@color/button_color</item> 
</style>
<style name="TextAppearance">
    <item name="android:textColor">@android:color/holo_red_dark</item>
</style>

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

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