简体   繁体   中英

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. I want the text to be black but it always shows up white.

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

<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

Solved it. changed my toolbar.xml file to this:

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

and

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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