2017-07-27 42 views
0

我的应用程序中有一个PopupWindow。 这就是我初始化: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(...)到PopupWindow的应该表现出来的.post(Runnable).runOnUiThread(Runnable)

  • 所有方法。

  • PopupWindowCompat.showAsDropdown(...)方法。

所有这些事情都没有帮助我。

同时一个PopupMenu的类正确地显示在相同的上下文。但我需要PopupWindow。

我应该怎么做才能显示PopupWindow?

+0

你叫.show()因为我看不出它有 – ADM

+0

PopupWindow没有.show()方法 –

+0

对不起我得到ListPopupWindow混淆。 – ADM

回答

0

按照这种方法,可以帮助你。

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); 

     } 

    }); 

} 
+1

如果您对代码的作用做了一些解释,那会更好吗? – AguThadeus

相关问题