弹出菜单项的更改文字大小 [英] changing text size of popup menu item

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

问题描述

我想改变弹出式菜单项的文字大小。我写了这个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.

这篇关于弹出菜单项的更改文字大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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