设置EditText的上下文菜单的图标

时间:2019-12-10 11:14:59

标签: android android-edittext android-contextmenu

我正在尝试设置Android EditText上下文菜单选项的图标,如下所示: enter image description here

我已经找到了如何添加自定义字符串选项的方法,但是我希望该选项本身是一个图标一个字符串。

文档尚不清楚EditText的上下文菜单是否可以包含图标。它确实指出某些菜单类型不会显示图标(ref here),而我只想知道上面的图像是否可以实现。

到目前为止我写的代码是:

// Adding the menu
menu.add(0, i, 0, stringOption); // stringOption like "bold" shows up

// Setting an icon doesn't
MenuItem item = menu.findItem(R.id.bold); // <---- correctly found
item.setIcon(R.drawable.ic_action_bold); // <---- icon doesn't show up, it's in my drawable folder as it shows up elsewhere in my app

我不需要操作栏或自定义弹出窗口,我想将其添加到EditText的现有上下文菜单中。

谢谢。

0 个答案:

没有答案