Home > Blockchain >  Menu item not showing titles in android
Menu item not showing titles in android

Time:02-14

I am currently adding the sorting functionality to my food app. But my app didn't show the menu items instead it shows a blank white menu.Any ways to resolve this problem?

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">

        <item
            android:id="@ id/sortName"
            android:title="Name" />

        <item
            android:id="@ id/sortRating"
            android:title="Rating" />

        <item
            android:id="@ id/sortCostAsc"
            android:title="Cost (low to high)" />

        <item
            android:id="@ id/sortCostDesc"
            android:title="Cost (high to low)" />

    </group>
</menu>

This is my menu layout.

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.FoodSpot" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/primary_violet</item>
        <item name="colorPrimaryVariant">@color/secondary_violet</item>
        <item name="colorOnPrimary">@color/black</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
        <item name="android:actionMenuTextColor">@color/black</item>
    </style>

    <style name="ThemeOverlay.AppCompat.navTheme">
        <!-- Color of text and icon when SELECTED -->
        <item name="colorPrimary">@color/secondary_violet</item>
        <!-- Background color when SELECTED -->
        <item name="colorControlHighlight">@color/secondary_violet</item>
    </style>
</resources>

This is my themes.xml . Based on some suggestion I've changed my colorOnPrimary and actionMenuTextColor. But Still same problem.

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
        inflater.inflate(R.menu.sort_menu,menu)
    }

Here, I inflate the menu layout.

setHasOptionsMenu(true)

And, also I added this inside my Oncreateview method of the fragment to enable the menu in the toolbar.

I've added the screenshot of my app here..

CodePudding user response:

try this way!! add to style

    <item name="android:itemTextAppearance">@style/menuStyle</item>

and add new style

    <style name="menuStyle" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">@color/your_color</item>
</style>

CodePudding user response:

<item name="colorOnPrimary">@color/white</item>

change this this causes the white color in your menu

CodePudding user response:

Try this!

<item name="colorOnPrimary">@color/white</item>

just update the color name here in your Menu Layout XML CODE and before Debugging the project Try "Clean Project". and after that Run your project might be it will work.

  • Related