search

Home  >  Q&A  >  body text

android - popupwindow的isShowing() 始终为false

点击某个按钮出现popupwindow,点击监听的代码如下:

if (wPopupWindow.isShowing()){
      wPopupWindow.dismiss();
}else{
      wPopupWindow.showAsDropDown(layoutFiltrate,0,0);
}

我输出日志,Popuowindow的isShowing()始终显示为false。麻烦各位多多指教。

阿神阿神2773 days ago703

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 15:18:21

    You should not use the isShowing() method of PopupWindow as the switch for showing and hiding, because if you have not called the showAsDropDown method, the return value of isShowing() must be false. You can customize a temporary boolean as a display switch, such as boolean isPopShowing=false; and then reset the display status through the method of isPopShowing=!isPopShowing

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 15:18:21

    Either the place where you output the log is wrong, or your wPopupWindow.showAsDropDown method has not been called at all.

      /**
         * <p>Indicate whether this popup window is showing on screen.</p>
         *
         * @return true if the popup is showing, false otherwise
         */
        public boolean isShowing() {
            return mIsShowing;
        }
    
      public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
        。。。
    
            mIsShowing = true;
        。。。

    reply
    0
  • Cancelreply