选定的弹出菜单项背景颜色设置 [英] Selected popup menu item background color set

查看:69
本文介绍了选定的弹出菜单项背景颜色设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想问有没有人可以更改所选菜单项的背景颜色?我在这个主题上搜索了很多,但我还没有找到任何可行的解决方案:(

I just one to ask that is there anybody who can chanse background color of the selected menuitem? I was searching a lot in this topic and I didnt find any working solution yet :(

所以我有一个带有 3dot imageview 的 recyclerview,当我单击此图像时,会显示一个弹出菜单.在我的列表中,我有项目并且所有项目都有一个状态,我使用这个弹出菜单来显示状态选项,但这些项目已经具有默认状态,我希望当弹出菜单出现时,manu 的默认项目具有不同的背景, 比其他人.

So I have a recyclerview with a 3dot imageview and when i click on this image a popup menu is show. In my list i have items and all item have a status and I use this popup menu to show status options, but the items already have default status and i would like that when popup menu appear, that defoult item of the manu has a different background, than the others.

I found one solution, that is with radiobuttons, so when menu item is selected, i set the item checket, so with the radiobutton is workign well, but that's not that I really want :/

I found one solution, that is with radiobuttons, so when menu item is selected, i set the item checket, so with the radiobutton is workign well, but that's not that I really want :/

我尝试过样式,如下所示:

I tried with styles, like following:

@style/PopupMenu

@style/PopupMenu

(对不起,我把代码贴在这里,但在我发布问题后,它没有很好地显示出来)

(sorry i paste it here the code, but after i publish the question it didnt show it well)

在可绘制文件中,我尝试了以下操作:

and in the drawable files i tried the following:

<item android:drawable="@color/light_blue" android:state_selected="true"/>
<item android:drawable="@color/light_blue" android:state_checked="true"/>
<item android:drawable="@color/transparent"/>

但对我来说似乎状态检查在背景中根本不起作用,只有单选按钮:(

But for me it seems like state checked not working at all with the background, only with the radio buttons :(

我还在 popup.setOnMenuItemClickListener 中尝试了以下内容:

I also tried inside my popup.setOnMenuItemClickListener the following:

val view = popup.menu.findItem(item.itemId).actionView as TextViewview.background = context.resources.getDrawable(R.drawable.custom_spinner_item_background_shape)

val view = popup.menu.findItem(item.itemId).actionView as TextView view.background = context.resources.getDrawable(R.drawable.custom_spinner_item_background_shape)

但是什么都没发生...

but nothing happend...

我也可以在单击项目时更改选择的突出显示颜色,但关闭菜单后此背景颜色消失.

I can aso change the selecting highlight color when item is clicked, but this background color disappear after dismiss the menu.

有没有人有解决这个问题的可行解决方案?

Does anyone has a working solution for this problem?

推荐答案

Style Named PopUp

Style Named PopUp

 <selector>
    <?xml version="1.0" encoding="utf-8"?>
    <item android:drawable="@color/light_blue" android:state_selected="true"/>
    <item android:drawable="@color/light_blue" android:state_checked="true"/>
    <item android:drawable="@color/transparent"/>
  </selector>

应用 android:background="@drawable/popup"

 <RadioButton
            android:id="@+id/rbID"
            android:text="check"
            android:background="@drawable/popup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="false"
            />

输出ss

未选中

已检查

chenge @style/PopupMenuandroid:background="@drawable/popup"

希望对你有帮助

这篇关于选定的弹出菜单项背景颜色设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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