changing text size of popup menu item

白昼怎懂夜的黑 提交于 2019-12-05 20:05:59
Dmide

Unfortunately, it's not trivial. To change MenuItem appearance, even in this simple case, you'll have to set a custom View to it. But that will work only if MenuItem is shown as action, i.e. not in a list, which is not your case. To customise the appearance of your list in PopupMenu you have to use PopUpWindow instead. See this answer for example.

In your case, as you want to add elements dynamically maybe the best solution will be to implement your own Adapter with proper getView() method and use it together with ListView and PopUpWindow.

I'm afraid it cannot be done like that. The closest thing you can do is the following:

  • Create a View previousView which implements R.id.actionbar_item
  • Use that View to manipulate the text size
  • Add an item to your PopupMenu via popupmenu.getMenu().add(Menu.NONE, 0 , Menu.NONE, "Exit");
  • Create a MenuItem object menuItem via MenuItem menuItem = popupmenu.getMenu().getItem(0);
  • Then set menuItem.setActionView(previousView);

This is your best bet, but I haven't tested it yet. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!