gpt4 book ai didi

android - 样式自定义弹出菜单

转载 作者:行者123 更新时间:2023-11-29 15:11:00 25 4
gpt4 key购买 nike

我有一个图像按钮,按下时会显示一个弹出菜单。

public void showMenu (View v){
PopupMenu popup = new PopupMenu(getBaseContext(), v);
popup.getMenuInflater().inflate(R.menu.menu_launch_page, popup.getMenu());
popup.show();

}

生成的菜单有深色背景。我如何设置弹出窗口的样式,以便更改背景颜色以及选择项目时的颜色。我正在使用 android:Theme.Holo.Light.NoActionBar,所以任何地方都没有涉及 Actionbar。

最佳答案

好的,你可以在这里试试,你也可以设置你的自定义适配器

您的 ButtonViewObject 是您单击以显示此弹出窗口的按钮

ListPopupWindow listPopupWindow = new ListPopupWindow(
ListPopupWindowAppActivity.this);

//here you can set your custom adapter aswell
listPopupWindow.setAdapter(new ArrayAdapter(
ListPopupWindowAppActivity.this,
R.layout.list_item, passyourarrayhere));
listPopupWindow.setAnchorView(yourButtonViewObject);
listPopupWindow.setWidth(300);
listPopupWindow.setHeight(400);

listPopupWindow.setModal(true);
listPopupWindow.setOnItemClickListener(
ListPopupWindowAppActivity.this);

//when you click on yourButtonViewObject show listPopupWindow like this
listPopupWindow.show();

//and in onItemClick overiden method do similar as you do in listview

关于android - 样式自定义弹出菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31473803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com