我想改变弹出式菜单项的文字大小。我写了这个code创建一个弹出菜单。但我的问题是我couldnot访问弹出菜单,即EXIT的TextView的,这样我可以使用
I want to change the text size of popup menu item. I have written this code to create a popup menu. But my problem is I couldnot access the textView of popupmenu ie"EXIT" so that i could use
exitItem.setTextSize(40);
//my code
popupmenu = new PopupMenu(MainActivity.this, findViewById(R.id.actionbar_item));
popupmenu.getMenu().add(Menu.NONE, 0, Menu.NONE, "Exit");
popupmenu.setOnMenuItemClickListener(this);
我还没有创建任何单独的XML文件中夸大这些项目。我想以编程方式做到这一点,因为这些popupitems是动态生成的。
I have not created any seperate xml file to inflate these items. I want to do it programatically as these popupitems are dynamically generated.
先谢谢了。
推荐答案
不幸的是,这不是小事。要更改菜单项
的外观,即使在这个简单的例子,你就会有一个自定义查看
设置它。但是,将工作只有菜单项
显示为行动,即不在列表中,这是不是你的情况。要自定义您的列表中的PopupMenu
的外观,你必须使用 PopUpWindow
来代替。请参见例如这个答案。
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.
在你的情况,只要你想添加元素动态也许是最好的解决办法是实现自己的适配器
适当 getView()
法和的ListView
和 PopUpWindow
。
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
.
相关推荐
最新文章