我正在应用程序中显示ContextMenu
。现在,当按下此ContextMenu
中的某个菜单项时,我想显示一个PopupWindow
。我发现了一些如何在互联网上使用PopupWindow
的例子,但我仍然有问题。我有以下代码:PopupView.showAtLocation是未定义的类型查看
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
popupView.showAtLocation(this.findViewById(R.id.main_layout), Gravity.CENTER, 0, 0);
以及活动的XML文件中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#232323" >
....
</RelativeLayout>
我想这应该工作,但我得到了以下错误消息:
“的方法showAtLocation (View,int,int,int)未定义为类型View“
这是什么意思?我给showAtLocation一个视图和三个整数,对吧?所以有什么问题?你们有什么想法吗?
哇感谢您的快速响应!愚蠢的是,我没有看到我自己:)。 – Zero