我的应用程序中有一个PopupWindow。我就是这样初始化它的:
final FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(200, 200));
hashTagsWindow = new PopupWindow(frameLayout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
hashTagsWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));这就是我试图展示的方式:
hashTagsWindow.showAsDropDown(binding.hash, 20, 20);但是我的PopupWindow不显示自己。
我已经试图解决的问题是什么?
.showAsDropDown(...)包装到.post(Runnable)和.runOnUiThread(Runnable)PopupWindowCompat.showAsDropdown(...)法所有这些都帮不了我。
同时,PopupMenu类在相同的上下文中正确显示。但我需要PopupWindow。
我该怎么做才能向PopupWindow展示呢?
发布于 2017-07-27 05:20:44
遵循这个方法,也许能帮你。
private void showPopupWindow(View view){
LayoutInflater mLayoutInflater=LayoutInflater.from(this);
View mView=mLayoutInflater.inflate(R.layout.pop_up_layout, null);
mPopupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
// mPopupWindow=new PopupWindow(mView,,LayoutParams.WRAP_CONTENT);
mPopupWindow.setContentView(mView);
Button mBtnCancel=(Button) mView.findViewById(R.id.btn_cancel);
mBtnCancel.setOnClickListener(this);
mPopupWindow.showAsDropDown(view, 0, 0, Gravity.LEFT);
mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
Drawable d = new ColorDrawable(Color.WHITE);
getWindow().setBackgroundDrawable(d);
}
});
}https://stackoverflow.com/questions/45341900
复制相似问题