问题描述
大家好,我需要从一个按钮,是在另一个popupWindow启动PopupMenu的,问题是,当我把这个按钮里面活动的根本观点,它的工作没有任何错误,但是当我想从另外一个抛砖引玉吧popupWindow它给出的错误。这里要说的是我用我的code:
Hi guys I need to initiate PopupMenu from a button that is inside another popupWindow, the problem is that when i'm placing this button inside activity's root view it worked without any error but when I want to initiate it from another popupWindow it give's error. here is my code that i'm using:
这是我PopupWindow:
this is my PopupWindow:
public void initiateSettingsPopupWindow() {
LayoutInflater settingsInflate = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View settingsLayout = settingsInflate.inflate(R.layout.settings_popup,
(ViewGroup) findViewById(R.id.fullscreen_content_controls));
PopupWindow swindo = new PopupWindow(settingsLayout, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT, true);
swindo.showAtLocation(settingsLayout, Gravity.BOTTOM,
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
swindo.setAnimationStyle(R.style.PopupWindowAnimation);
LinearLayout settingsLinear = (LinearLayout) settingsLayout
.findViewById(R.id.settingseditback);
settingsLinear.setOnClickListener(this);
}
这是我的PopupMenu code:
and this is my PopupMenu code:
public void showSettingsPopup(View v) {
PopupMenu popup = new PopupMenu(getBaseContext(), v);
popup.setOnMenuItemClickListener(this);
popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
popup.show();
}
和这里是我的xml文件:
and here is my xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settingseditback"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/fullscreen_content_controls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#ededed"
android:orientation="vertical" >
.
.
.
<ImageView
android:id="@+id/IVoptionsMenu"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_gravity="center_horizontal"
android:layout_weight="25"
android:onClick="showSettingsPopup"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:src="@drawable/ic_actionbar_overflow_dark" >
</ImageView>
</LinearLayout>
</LinearLayout>
这是什么问题?而这个问题已经被问here但目前还没有答案。我想这是由于在上网备至,但没有成功呢。
What is the problem? and this question is already asked here but no answer yet.I tried every possible way that is given in internet,but no success yet.
请给我一个解决方案,我真的卡在这个错误。
Please give me a solution i'm really stuck in this error.
推荐答案
终于让我找到了解决办法通过一个小技巧,我分享它,如果有人需要它。我的解决方案不是那么大,但它的作品没有任何视觉差异和问题,所以也许在某些情况下帮助。我的主XML文件,并与在PopupWindow原来的按钮完全一样的地方创建了一个按钮,并在PopupMenu的code我换成V配合隐形按钮参考,这是我的code:
Finally i found the solution by a little trick and i'm sharing it so if someone need it. My solution isn't so great but it works without any visual difference and problem, so maybe it help in some case.I created one button in main xml file and in exact same place with the original button in PopupWindow, and in PopupMenu code I replaced v with reference for invisible button, here is my code:
public void showSettingsPopup2(View v) {
PopupMenu popup = new PopupMenu(getBaseContext(), findViewById(R.id.IVoptionsMenuInvis));
popup.setOnMenuItemClickListener(this);
popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
popup.show();
}
这篇关于从另一个PopupWindow内启动的PopupMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!