0

The manifest specifies a theme for the entire application

android:theme="@style/Theme.MyApplication"

In themes.xml, this theme inherits:

<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.NoActionBar"></style>

Instead of ActionBar, I put the ToolBar in the activity in which I changed the theme:

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:theme="@style/ThemeForMyMenu"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="#47A0FF"/>

In themes.xml, the ThemeForMyMenu is described as follows:

<style name="ThemeForMyMenu" parent="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">
    <item name="android:actionMenuTextColor">#000000</item>
</style>

As a result, it turns out that I use a light theme for the entire application, and a dark one for the ToolBar in which I change the actionMenuTextColor to black. I create a menu file in which I create two items. one item is displayed on the ToolBar, and the other remains in the menu

<item android:title="О программе"
    app:showAsAction="always"
    android:id="@+id/about"
    />
<item android:title="Выход"
    android:id="@+id/exit"
    app:showAsAction="never"/>

The item that was displayed on the ToolBar turned black (# 000000), and the item that remained in the menu has white color and merges with the background of the menu (it is not visible). I need to change the menu text color and menu background color. I couldn't find a way to do this. Tell me how to change the text color (inside the menu) and the background color of the menu

1 Answer 1

0

You can add the app:popupTheme attribute in your Toolbar.

<androidx.appcompat.widget.Toolbar
    app:popupTheme="@style/AppTheme.PopupOverlay" 
    ../>

with:

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary" >
    <item name="android:textColor">@color/...</item>   <!-- text color -->
    <item name="colorSurface">@color/...</item>  <!-- background -->
</style>

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.