How to change OncreateOptionsMenu top and bottom color in android studio?

Issue

I have a OncreateOptionsMenu where I can change test color and background but not able to change top and bottom grey color into blue color in the below image. Any suggestions and solutions are welocme.

Image:

enter image description here

Theme:

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/background</item>
    <item name="colorPrimaryVariant">@color/background</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/background</item>
    <item name="colorSecondaryVariant">@color/background</item>
    <item name="colorOnSecondary">@color/background</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Dropdown Top and Bottom Color. -->
    <item name="colorSurface">@color/background</item>
    <!-- OncreateOptionsMenu Style -->
    <item name="android:itemTextAppearance">@style/OptionsMenuStyle</item>
    <item name="android:itemBackground">@color/background</item>
</style>

<!-- OncreateOptionsMenu Style -->
<style name="OptionsMenuStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
    <item name="android:textStyle">italic</item>
</style>

Solution

Try this!

Following is the styles.xml file.

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- This is the styling for action bar -->
        <item name="actionBarStyle">@style/MyActionBar</item>
        <!--To change the text styling of options menu items</item>-->
        <item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
        <!--To change the background of options menu-->
        <item name="android:itemBackground">@color/skyBlue</item>
    </style>

    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="background">@color/red</item>
        <item name="titleTextStyle">@style/MyActionBarTitle</item>
    </style>

    <style name="MyActionBarTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/white</item>
    </style>

    <style name="MyActionBar.MenuTextStyle"
        parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">25sp</item>
    </style>
</resources>

Answered By – Josh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published