菜单项的标题未显示 [英] Menu Item's Tittle Not Showing

查看:89
本文介绍了菜单项的标题未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

菜单项的标题未显示在片段内.我在菜单文件中有两个项目,第一个是带有图标和标签的 showAsAction=always 以在工具栏中显示图标.第二个只有标题.

Menu item's title is not showing inside fragment. I have two items in menu file, The first one is with icon and tag showAsAction=always to show the icon in toolbar. The second one is only with tittle.

我不知道这里出了什么问题.

I don't know what's going wrong here.

菜单项的所有操作都有效.例如下面.

All actions with the menu items is working. E.g below.

menu_sale.xml

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

    <item android:title="Scanner"
        android:id="@+id/miScanner"
        android:icon="@drawable/ic_baseline_qr_code_scanner"
        android:iconTint="@color/white"
        app:showAsAction="always"
        />

    <item
        android:title="Add Credit Record"
        android:id="@+id/miAddCreditRecord"
        />

</menu>

没有 showAsAction='always' 的项目没有在我的应用中显示标题.

The item without showAsAction='always' not showing the title in my app.

我的 java 代码来膨胀菜单.

My java code to inflate the menu.

@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_sale, menu);
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.miScanner:
            scanCode();
            break;
        case R.id.miAddCreditRecord:
            showBottomSheetDialog();
            break;
    }
    return super.onOptionsItemSelected(item);
}

我的主题 theme.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.AzmiUnaniStore" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</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. -->
    </style>
    
    <style name="NoActionBar" parent="Theme.AzmiUnaniStore">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

    <style name="BottomSheetDialogTheme" parent="Theme.Design.BottomSheetDialog">
    </style>

    <style name="BottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
        
    </style>
    
</resources>

可能性

标题显示完美,但当操作菜单颜色为白色且背景也是白色时,我看不到标题.

POSSIBILITIES

The tittle is showing perfectly but when the action menu colour is white and the background is also white that's is the I am not able to see the tittle.

谢谢

推荐答案

问题是弹出菜单中的文本颜色.
MaterialToolbar 中添加 app:popupTheme 属性.

The issue is the text color in the popup menu.
Add the app:popupTheme attribute in your MaterialToolbar.

    <com.google.android.material.appbar.MaterialToolbar
        app:popupTheme="@style/AppTheme.PopupOverlay" 
        ../>

与:

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

这篇关于菜单项的标题未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆