久久99久久人婷婷精品综合_超碰aⅴ人人做人人爽欧美_亚洲电影第三页_日韩欧美一中文字暮专区_波多野结衣的一区二区三区_婷婷在线播放_人人视频精品_国产精品日韩精品欧美精品_亚洲免费黄色_欧美性猛交xxxxxxxx

在android使用PopupWindow時(shí)出現(xiàn)返回鍵消失如何解決

在android使用PopupWindow時(shí)出現(xiàn)返回鍵消失如何解決?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)公司從2013年成立,先為宜君等服務(wù)建站,宜君等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為宜君企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

preparePopup方法。

 public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
    if (isShowing() || mContentView == null) {
      return;
    }

    registerForScrollChanged(anchor, xoff, yoff, gravity);

    mIsShowing = true;
    mIsDropdown = true;

    WindowManager.LayoutParams p = createPopupLayout(anchor.getWindowToken());
    preparePopup(p);

    updateAboveAnchor(findDropDownPosition(anchor, p, xoff, yoff, gravity));

    if (mHeightMode < 0) p.height = mLastHeight = mHeightMode;
    if (mWidthMode < 0) p.width = mLastWidth = mWidthMode;

    p.windowAnimations = computeAnimationResource();

    invokePopup(p);
 }

再看preparePopup方法

  /**
   * <p>Prepare the popup by embedding in into a new ViewGroup if the
   * background drawable is not null. If embedding is required, the layout
   * parameters' height is modified to take into account the background's
   * padding.</p>
   *
   * @param p the layout parameters of the popup's content view
   */
  private void preparePopup(WindowManager.LayoutParams p) {
    if (mContentView == null || mContext == null || mWindowManager == null) {
      throw new IllegalStateException("You must specify a valid content view by "
          + "calling setContentView() before attempting to show the popup.");
    }

    if (mBackground != null) {
      final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams();
      int height = ViewGroup.LayoutParams.MATCH_PARENT;
      if (layoutParams != null &&
          layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
        height = ViewGroup.LayoutParams.WRAP_CONTENT;
      }

      // when a background is available, we embed the content view
      // within another view that owns the background drawable
      PopupViewContainer popupViewContainer = new PopupViewContainer(mContext);
      PopupViewContainer.LayoutParams listParams = new PopupViewContainer.LayoutParams(
          ViewGroup.LayoutParams.MATCH_PARENT, height
      );
      popupViewContainer.setBackground(mBackground);
      popupViewContainer.addView(mContentView, listParams);

      mPopupView = popupViewContainer;
    } else {
      mPopupView = mContentView;
    }

    mPopupView.setElevation(mElevation);
    mPopupViewInitialLayoutDirectionInherited =
        (mPopupView.getRawLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT);
    mPopupWidth = p.width;
    mPopupHeight = p.height;
  }

上面可以看到mBackground不為空的時(shí)候,會PopupViewContainer作為mContentView的Parent,下面看看PopupViewContainer到底干了什么

  private class PopupViewContainer extends FrameLayout {
    private static final String TAG = "PopupWindow.PopupViewContainer";

    public PopupViewContainer(Context context) {
      super(context);
    }

    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
      if (mAboveAnchor) {
        // 1 more needed for the above anchor state
        final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
        View.mergeDrawableStates(drawableState, ABOVE_ANCHOR_STATE_SET);
        return drawableState;
      } else {
        return super.onCreateDrawableState(extraSpace);
      }
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {  // 這個(gè)方法里面實(shí)現(xiàn)了返回鍵處理邏輯,會調(diào)用dismiss
      if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (getKeyDispatcherState() == null) {
          return super.dispatchKeyEvent(event);
        }

        if (event.getAction() == KeyEvent.ACTION_DOWN
            && event.getRepeatCount() == 0) {
          KeyEvent.DispatcherState state = getKeyDispatcherState();
          if (state != null) {
            state.startTracking(event, this);
          }
          return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
          KeyEvent.DispatcherState state = getKeyDispatcherState();
          if (state != null && state.isTracking(event) && !event.isCanceled()) {
            dismiss();
            return true;
          }
        }
        return super.dispatchKeyEvent(event);
      } else {
        return super.dispatchKeyEvent(event);
      }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
      if (mTouchInterceptor != null && mTouchInterceptor.onTouch(this, ev)) {
        return true;
      }
      return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) { // 這個(gè)方法里面實(shí)現(xiàn)點(diǎn)擊消失邏輯
      final int x = (int) event.getX();
      final int y = (int) event.getY();
      
      if ((event.getAction() == MotionEvent.ACTION_DOWN)
          && ((x < 0) || (x >= getWidth()) || (y < 0) || (y >= getHeight()))) {
        dismiss();
        return true;
      } else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
        dismiss();
        return true;
      } else {
        return super.onTouchEvent(event);
      }
    }

    @Override
    public void sendAccessibilityEvent(int eventType) {
      // clinets are interested in the content not the container, make it event source
      if (mContentView != null) {
        mContentView.sendAccessibilityEvent(eventType);
      } else {
        super.sendAccessibilityEvent(eventType);
      }
    }
  }

看到上面紅色部分的標(biāo)注可以看出,這個(gè)內(nèi)部類里面封裝了處理返回鍵退出和點(diǎn)擊外部退出的邏輯,但是這個(gè)類對象的構(gòu)造過程中(preparePopup方法中)卻有個(gè)mBackground != null的條件才會創(chuàng)建

而mBackground對象在setBackgroundDrawable方法中被賦值,看到這里應(yīng)該就明白一切了。

  /**
   * Specifies the background drawable for this popup window. The background
   * can be set to {@code null}.
   *
   * @param background the popup's background
   * @see #getBackground()
   * @attr ref android.R.styleable#PopupWindow_popupBackground
   */
  public void setBackgroundDrawable(Drawable background) {
    mBackground = background;
    // 省略其他的
  }

setBackgroundDrawable方法除了被外部調(diào)用,構(gòu)造方法中也會調(diào)用,默認(rèn)是從系統(tǒng)資源中取的

  /**
   * <p>Create a new, empty, non focusable popup window of dimension (0,0).</p>
   * 
   * <p>The popup does not provide a background.</p>
   */
  public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

    final TypedArray a = context.obtainStyledAttributes(
        attrs, R.styleable.PopupWindow, defStyleAttr, defStyleRes);
    final Drawable bg = a.getDrawable(R.styleable.PopupWindow_popupBackground);
    mElevation = a.getDimension(R.styleable.PopupWindow_popupElevation, 0);
    mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);

    final int animStyle = a.getResourceId(R.styleable.PopupWindow_popupAnimationStyle, -1);
    mAnimationStyle = animStyle == R.style.Animation_PopupWindow &#63; -1 : animStyle;

    a.recycle();

    setBackgroundDrawable(bg);
  }

有些版本沒有,android6.0版本preparePopup如下: 

  /**
   * Prepare the popup by embedding it into a new ViewGroup if the background
   * drawable is not null. If embedding is required, the layout parameters'
   * height is modified to take into account the background's padding.
   *
   * @param p the layout parameters of the popup's content view
   */
  private void preparePopup(WindowManager.LayoutParams p) {
    if (mContentView == null || mContext == null || mWindowManager == null) {
      throw new IllegalStateException("You must specify a valid content view by "
          + "calling setContentView() before attempting to show the popup.");
    }

    // The old decor view may be transitioning out. Make sure it finishes
    // and cleans up before we try to create another one.
    if (mDecorView != null) {
      mDecorView.cancelTransitions();
    }

    // When a background is available, we embed the content view within
    // another view that owns the background drawable.
    if (mBackground != null) {
      mBackgroundView = createBackgroundView(mContentView);
      mBackgroundView.setBackground(mBackground);
    } else {
      mBackgroundView = mContentView;
    }

    mDecorView = createDecorView(mBackgroundView);

    // The background owner should be elevated so that it casts a shadow.
    mBackgroundView.setElevation(mElevation);

    // We may wrap that in another view, so we'll need to manually specify
    // the surface insets.
    final int surfaceInset = (int) Math.ceil(mBackgroundView.getZ() * 2);
    p.surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset);
    p.hasManualSurfaceInsets = true;

    mPopupViewInitialLayoutDirectionInherited =
        (mContentView.getRawLayoutDirection() == View.LAYOUT_DIRECTION_INHERIT);
    mPopupWidth = p.width;
    mPopupHeight = p.height;
  }

這里實(shí)現(xiàn)返回鍵監(jiān)聽的代碼是mDecorView = createDecorView(mBackgroundView),這個(gè)并沒有受到那個(gè)mBackground變量的控制

關(guān)于在android使用PopupWindow時(shí)出現(xiàn)返回鍵消失如何解決問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

文章標(biāo)題:在android使用PopupWindow時(shí)出現(xiàn)返回鍵消失如何解決
網(wǎng)站鏈接:http://www.js-pz168.com/article26/pcsgjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站外貿(mào)網(wǎng)站建設(shè)網(wǎng)站營銷搜索引擎優(yōu)化商城網(wǎng)站標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
久久99久久人婷婷精品综合_超碰aⅴ人人做人人爽欧美_亚洲电影第三页_日韩欧美一中文字暮专区_波多野结衣的一区二区三区_婷婷在线播放_人人视频精品_国产精品日韩精品欧美精品_亚洲免费黄色_欧美性猛交xxxxxxxx
激情小说亚洲一区| 国产伦精品一区二区三区高清| 999热视频| 欧美日本国产精品| 欧美日韩一级片在线观看| 久久亚洲二区三区| 一区二区视频在线| 国产原创一区二区| 国产精品一区而去| 一本色道亚洲精品aⅴ| 精品欧美乱码久久久久久1区2区 | 国产日韩欧美精品在线| 亚洲国产精品尤物yw在线观看| 精品一二线国产| 成人免费看片网址| 色94色欧美sute亚洲线路一ni | 国产成人h网站| 欧美激情视频一区二区三区| 欧美嫩在线观看| 亚洲欧洲www| 久久国产精品区| 国产私拍一区| 欧美美女喷水视频| 亚洲日本成人在线观看| 国产精品香蕉一区二区三区| 欧美极品日韩| 日韩欧美国产电影| 亚洲与欧洲av电影| 99久久精品国产导航| 伊人久久大香线蕉精品| 久久九九全国免费| 精品国产髙清在线看国产毛片| 亚洲精品视频一区二区| 成人午夜电影久久影院| 亚洲欧美日韩精品久久久| 久久香蕉国产线看观看99| 全部av―极品视觉盛宴亚洲| 国产视频一区二区不卡| 在线91免费看| 亚洲第一搞黄网站| dy888夜精品国产专区| 欧美日韩国产区一| 亚洲一二三区视频在线观看| 91在线国产福利| 欧美日韩一区二区三区在线看| 亚洲欧美乱综合| 99综合影院在线| 欧美日韩在线播放| 亚洲小少妇裸体bbw| www.久久艹| 欧美一级免费观看| 日本vs亚洲vs韩国一区三区二区 | 国产精品理伦片| 国产成人精品亚洲777人妖 | 亚洲成年人影院| 国产精品av一区| 欧美成人精品福利| 日本欧美加勒比视频| 欧美日韩在线高清| 久久九九久久九九| 国产福利一区在线| 欧美综合视频在线观看| 亚洲精品乱码久久久久久久久| 91免费在线播放| 日韩欧美在线观看一区二区三区| 日韩高清不卡一区二区| 欧美一二三区| 中文字幕va一区二区三区| 成人国产精品免费| 欧美人牲a欧美精品| 日韩黄色免费电影| 午夜一区二区三视频在线观看| 国产精品嫩草久久久久| 成人av先锋影音| 91精品午夜视频| 久久精品国产精品亚洲精品| 亚洲一一在线| 亚洲尤物在线视频观看| 精品日本一区二区三区在线观看 | 亚洲视频导航| 一区二区三区久久久| 国产日韩精品久久| 久久九九久久九九| av电影天堂一区二区在线| 欧美一级片在线观看| 国产伦精品一区二区三区免费| 在线精品视频一区二区| 亚洲国产精品久久久男人的天堂| 久久视频在线观看中文字幕| 国产精品拍天天在线| 97人人干人人| 久久久久久久久久电影| 白白色亚洲国产精品| 日韩午夜电影av| 国产成人av电影在线观看| 欧美挠脚心视频网站| 国产揄拍国内精品对白| 欧美少妇xxx| 久久66热re国产| 欧美日韩国产综合视频在线观看 | 91色|porny| 久久久精品欧美丰满| 97久久精品人人澡人人爽| 26uuuu精品一区二区| 91麻豆免费视频| 国产色产综合色产在线视频 | 精品久久久久久综合日本欧美| 国产v综合v亚洲欧| 日韩欧美亚洲另类制服综合在线| 国产成人av电影在线观看| 日韩三级视频在线看| 成人av免费观看| 久久久不卡网国产精品二区| 51国产成人精品午夜福中文下载| 久久精品在线观看| 国产精品一区二区三区不卡| 国产精品国产三级国产普通话三级 | a在线播放不卡| 欧美精品一区视频| 91啪九色porn原创视频在线观看| 国产三级久久久| 国产伦视频一区二区三区| 最近日韩中文字幕| 日本一区高清在线视频| 午夜欧美电影在线观看| 色噜噜狠狠色综合中国| 久久成人羞羞网站| 91精品国产高清一区二区三区蜜臀| 国产经典欧美精品| 精品成人免费观看| 国产精品日韩一区二区免费视频| 中文字幕亚洲电影| 日韩福利在线| 美女国产一区二区| 制服丝袜在线91| 99re热这里只有精品视频| 国产精品日产欧美久久久久| 免费在线国产精品| 丝袜美腿亚洲一区| 欧美乱妇23p| 99精品视频在线播放观看| 国产精品免费人成网站| 日本一区二区三区视频在线播放| 日韩国产欧美在线视频| 911国产精品| 91美女精品福利| 一区二区三区四区精品在线视频| 一本一道综合狠狠老| 国产精品综合一区二区三区| 337p日本欧洲亚洲大胆精品| 国产私拍一区| 日韩高清电影一区| 日韩一区国产二区欧美三区| 91视频在线免费观看| 亚洲久本草在线中文字幕| 欧美亚洲国产一区在线观看网站| 成人综合婷婷国产精品久久免费| 亚洲国产精品99久久久久久久久| 日本视频精品一区| 久久精品国产精品亚洲精品| 精品国产亚洲一区二区三区在线观看| 国产视频在线观看一区| 视频一区二区三区入口| 日韩午夜激情视频| 久久久久久久免费| 老司机免费视频一区二区三区| 精品卡一卡二卡三卡四在线| 欧美日韩成人一区二区三区| 精品制服美女丁香| 久久精品在线免费观看| 亚洲国产欧美不卡在线观看| 国产成人免费视频一区| ...av二区三区久久精品| 在线一区二区三区四区五区 | 国产欧美视频一区二区| 亚洲欧美成人一区| 大陆成人av片| 一区二区三区精品在线| 欧美精品亚洲一区二区在线播放| 国产精品播放| 美国一区二区三区在线播放| 国产日韩精品一区| 色哟哟国产精品免费观看| 93久久精品日日躁夜夜躁欧美| 亚洲成a人v欧美综合天堂| 精品三级在线观看| 视频一区三区| 99视频一区二区三区| 亚洲成人av电影在线| 久久品道一品道久久精品| 婷婷四房综合激情五月| 成人精品在线视频观看| 亚洲电影第三页| 久久午夜电影网| 色综合久久综合网欧美综合网| 91青青草免费在线看| 免费一级欧美片在线观看| 国产精品视频yy9299一区| 欧美日韩激情一区二区| 六月婷婷久久|