简体   繁体   English

菜单组中的Android项目文本和图标颜色更改

[英]Android item in menu group text and icon color changing

I have a menu with groups that contain items. 我有一个菜单,其中包含包含项目的组。 These items change color, including their icon, like visited links in HTML. 这些项目会更改颜色,包括其图标,例如HTML中的访问链接。 I never specified this behavior or color (which I can't find in my resources at all). 我从来没有指定这种行为或颜色(我在资源中根本找不到)。

Its applying a tint to the whole item , including the icon after I click on it. 单击它后,它会将色调应用于整个item ,包括图标。 Here is my XML. 这是我的XML。

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="none">
        <item
            android:id="@+id/action_one"
            android:icon="@drawable/ic_one"
            android:title="@string/one"/>
        <item
            android:id="@+id/action_two"
            android:icon="@drawable/two"
            android:title="@string/two" />
    </group>

</menu>

I also don't see any attribute to stop this behavior? 我也没有看到任何可阻止此行为的属性? Do I have to modify an app theme or something to disable this? 我是否需要修改应用程序主题或禁用此主题的内容? I want all of my items to have the same color, even after they are clicked on. 我希望我所有的项目都具有相同的颜色,即使在单击它们之后也是如此。

The issue was that the menu item was being selected programmatically, which I didn't realize was happening. 问题在于菜单项是通过编程方式选择的,但我没有意识到这种情况正在发生。

...

new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
//                    menuItem.setChecked(true); <-- was changing the color

...

Commenting out this line leaves the color as the default color. 注释掉该行,将颜色保留为默认颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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