当前位置: 首页>>代码示例>>Java>>正文


Java PopupWindowCompat类代码示例

本文整理汇总了Java中android.support.v4.widget.PopupWindowCompat的典型用法代码示例。如果您正苦于以下问题:Java PopupWindowCompat类的具体用法?Java PopupWindowCompat怎么用?Java PopupWindowCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PopupWindowCompat类属于android.support.v4.widget包,在下文中一共展示了PopupWindowCompat类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showAtAnchorView

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
/**
 * 相对anchor view显示,适用 宽高不为match_parent
 * <p>
 * 注意:如果使用 VerticalGravity 和 HorizontalGravity 时,请确保使用之后 PopupWindow 没有超出屏幕边界,
 * 如果超出屏幕边界,VerticalGravity 和 HorizontalGravity 可能无效,从而达不到你想要的效果。
 *
 * @param anchor
 * @param vertGravity  垂直方向的对齐方式
 * @param horizGravity 水平方向的对齐方式
 * @param x            水平方向的偏移
 * @param y            垂直方向的偏移
 */
public void showAtAnchorView(@NonNull View anchor, @VerticalGravity final int vertGravity, @HorizontalGravity int horizGravity, int x, int y) {
    if (mPopupWindow == null) {
        return;
    }
    mAnchorView = anchor;
    mOffsetX = x;
    mOffsetY = y;
    mVerticalGravity = vertGravity;
    mHorizontalGravity = horizGravity;
    isOnlyGetWH = false;
    //处理背景变暗
    handleBackgroundDim();
    final View contentView = getContentView();
    addGlobalLayoutListener(contentView);
    contentView.measure(0, View.MeasureSpec.UNSPECIFIED);
    final int measuredW = contentView.getMeasuredWidth();
    final int measuredH = contentView.getMeasuredHeight();

    x = calculateX(anchor, horizGravity, measuredW, x);
    y = calculateY(anchor, vertGravity, measuredH, y);
    Log.i(TAG, "showAtAnchorView: w=" + measuredW + ",y=" + measuredH);
    PopupWindowCompat.showAsDropDown(mPopupWindow, anchor, x, y, Gravity.NO_GRAVITY);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:EasyPopup.java

示例2: showAsDropDown

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public void showAsDropDown(View anchor, int offsetX, int offsetY, int gravity) {
    if (mPopupWindow != null) {
        handleBackgroundDim();
        mAnchorView = anchor;
        mOffsetX = offsetX;
        mOffsetY = offsetY;
        isOnlyGetWH = true;
        addGlobalLayoutListener(mPopupWindow.getContentView());
        PopupWindowCompat.showAsDropDown(mPopupWindow, anchor, offsetX, offsetY, gravity);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:EasyPopup.java

示例3: setSupportOverlapAnchor

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public void setSupportOverlapAnchor(boolean overlapAnchor) {
    if (COMPAT_OVERLAP_ANCHOR) {
        this.mOverlapAnchor = overlapAnchor;
    } else {
        PopupWindowCompat.setOverlapAnchor(this, overlapAnchor);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:AppCompatPopupWindow.java

示例4: showPopupWindow

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
/**
 * Shows a PopupWindow at the anchor view with given window height and list size.
 */
private void showPopupWindow(View button, int height, int listSize,
                             boolean useDefaultInflater) {
    final Context context = button.getContext();
    final ListView listView = new ListView(context);
    final BaseAdapter adapter;
    if (useDefaultInflater) {
        adapter = new ArrayAdapter<>(context,
                android.R.layout.simple_list_item_1, android.R.id.text1,
                createSampleArray(listSize));
    } else {
        adapter = new MyAdapter(button.getContext(), createSampleArray(listSize));
    }
    listView.setAdapter(adapter);


    listView.setVerticalScrollBarEnabled(true);
    listView.setBackgroundColor(0xFFFFFF);
    final PopupWindow window = new PopupWindow(listView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            height,
            true);
    window.setBackgroundDrawable(context.getResources().getDrawable(
            android.R.drawable.editbox_background));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (window.isShowing()) {
                window.dismiss();
            }
        }
    });
    PopupWindowCompat.showAsDropDown(window, button, 0, 0, Gravity.NO_GRAVITY);
}
 
开发者ID:google,项目名称:talkback,代码行数:37,代码来源:PopupViewTest.java

示例5: getSupportOverlapAnchor

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public boolean getSupportOverlapAnchor()
{
    if (COMPAT_OVERLAP_ANCHOR)
    {
        return mOverlapAnchor;
    } else
    {
        return PopupWindowCompat.getOverlapAnchor(this);
    }
}
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:11,代码来源:AppCompatPopupWindow.java

示例6: setSupportOverlapAnchor

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public void setSupportOverlapAnchor(boolean flag)
{
    if (COMPAT_OVERLAP_ANCHOR)
    {
        mOverlapAnchor = flag;
        return;
    } else
    {
        PopupWindowCompat.setOverlapAnchor(this, flag);
        return;
    }
}
 
开发者ID:Hamz-a,项目名称:MyCTFWriteUps,代码行数:13,代码来源:AppCompatPopupWindow.java

示例7: onClick

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
@Override public void onClick(View v) {
    if (clickListener != null) {
        clickListener.onClick(v);
    }
    //using 8dip on axisX offset to make dropdown view visually be at start of dropdown itself
    //using 4dip on axisY offset to make space between dropdown view and dropdown itself
    //all offsets are necessary because of the dialog_holo_light_frame to display correctly on screen(shadow was made by inset)
    int gravity;
    int axisXOffset;
    if (dropDownViewWidth + getX() > screenWidth) {
        gravity = Gravity.TOP | Gravity.END;
        axisXOffset = DimenUtils.dpToPixels(8);
    }
    else {
        gravity = Gravity.TOP | Gravity.START;
        axisXOffset = -DimenUtils.dpToPixels(8);
    }
    int axisYOffset = DimenUtils.dpToPixels(4);
    switch (expandDirection) {
        case UP:
            PopupWindowCompat.showAsDropDown(dropdownWindow, v,
                    axisXOffset,
                    -dropDownViewHeight - getMeasuredHeight() - axisYOffset * 3,
                    gravity);
            break;
        case DOWN:
            PopupWindowCompat.showAsDropDown(dropdownWindow, v,
                    axisXOffset,
                    -axisYOffset,
                    gravity);
            break;
    }
    setSelected(true);
}
 
开发者ID:Bearded-Hen,项目名称:Android-Bootstrap,代码行数:35,代码来源:BootstrapDropDown.java

示例8: show

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public void show(@NonNull View anchorView, @Nullable Callback callback) {
    this.callback = callback;
    popupWindowHost = new PopupWindow(this, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, true);
    popupWindowHost.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindowHost.setElevation(getResources().getDimension(R.dimen.overflow_elevation));
    }
    PopupWindowCompat.setOverlapAnchor(popupWindowHost, true);
    PopupWindowCompat.showAsDropDown(popupWindowHost, anchorView, 0, 0, Gravity.END);
}
 
开发者ID:wikimedia,项目名称:apps-android-wikipedia,代码行数:12,代码来源:ExploreOverflowView.java

示例9: showOnAnchor

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
/**
 * Show at relative position to anchor View with translation.
 * @param anchor Anchor View
 * @param vertPos Vertical Position Flag
 * @param horizPos Horizontal Position Flag
 * @param x Translation X
 * @param y Translation Y
 * @param fitInScreen Automatically fit in screen or not
 */
public void showOnAnchor(@NonNull View anchor, @VerticalPosition int vertPos, @HorizontalPosition int horizPos, int x, int y, boolean fitInScreen) {
    setClippingEnabled(fitInScreen);
    View contentView = getContentView();
    contentView.measure(makeDropDownMeasureSpec(getWidth()), makeDropDownMeasureSpec(getHeight()));
    final int measuredW = contentView.getMeasuredWidth();
    final int measuredH = contentView.getMeasuredHeight();
    if (!fitInScreen) {
        final int[] anchorLocation = new int[2];
        anchor.getLocationInWindow(anchorLocation);
        x += anchorLocation[0];
        y += anchorLocation[1] + anchor.getHeight();
    }
    switch (vertPos) {
        case VerticalPosition.ABOVE:
            y -= measuredH + anchor.getHeight();
            break;
        case VerticalPosition.ALIGN_BOTTOM:
            y -= measuredH;
            break;
        case VerticalPosition.CENTER:
            y -= anchor.getHeight()/2 + measuredH/2;
            break;
        case VerticalPosition.ALIGN_TOP:
            y -= anchor.getHeight();
            break;
        case VerticalPosition.BELOW:
            // Default position.
            break;
    }
    switch (horizPos) {
        case HorizontalPosition.LEFT:
            x -= measuredW;
            break;
        case HorizontalPosition.ALIGN_RIGHT:
            x -= measuredW - anchor.getWidth();
            break;
        case HorizontalPosition.CENTER:
            x += anchor.getWidth()/2 - measuredW/2;
            break;
        case HorizontalPosition.ALIGN_LEFT:
            // Default position.
            break;
        case HorizontalPosition.RIGHT:
            x += anchor.getWidth();
            break;
    }
    if (fitInScreen) {
        PopupWindowCompat.showAsDropDown(this, anchor, x, y, Gravity.NO_GRAVITY);
    } else {
        showAtLocation(anchor, Gravity.NO_GRAVITY, x, y);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:62,代码来源:RelativePopupWindow.java

示例10: getSupportOverlapAnchor

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public boolean getSupportOverlapAnchor() {
    if (COMPAT_OVERLAP_ANCHOR) {
        return this.mOverlapAnchor;
    }
    return PopupWindowCompat.getOverlapAnchor(this);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:AppCompatPopupWindow.java

示例11: AppCompatPopupWindow

import android.support.v4.widget.PopupWindowCompat; //导入依赖的package包/类
public AppCompatPopupWindow(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
  super(paramContext, paramAttributeSet, paramInt);
  TintTypedArray localTintTypedArray = TintTypedArray.obtainStyledAttributes$1a6c1917(paramContext, paramAttributeSet, R.styleable.PopupWindow, paramInt);
  boolean bool;
  if (localTintTypedArray.hasValue(R.styleable.PopupWindow_overlapAnchor))
  {
    bool = localTintTypedArray.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);
    if (!COMPAT_OVERLAP_ANCHOR) {
      break label136;
    }
    this.mOverlapAnchor = bool;
  }
  for (;;)
  {
    setBackgroundDrawable(localTintTypedArray.getDrawable(R.styleable.PopupWindow_android_popupBackground));
    localTintTypedArray.mWrapped.recycle();
    if (Build.VERSION.SDK_INT < 14) {}
    try
    {
      Field localField1 = PopupWindow.class.getDeclaredField("mAnchor");
      localField1.setAccessible(true);
      Field localField2 = PopupWindow.class.getDeclaredField("mOnScrollChangedListener");
      localField2.setAccessible(true);
      localField2.set(this, new ViewTreeObserver.OnScrollChangedListener()
      {
        public final void onScrollChanged()
        {
          try
          {
            WeakReference localWeakReference = (WeakReference)this.val$fieldAnchor.get(jdField_this);
            if (localWeakReference != null)
            {
              if (localWeakReference.get() == null) {
                return;
              }
              this.val$originalListener.onScrollChanged();
              return;
            }
          }
          catch (IllegalAccessException localIllegalAccessException) {}
        }
      });
      return;
    }
    catch (Exception localException)
    {
      label136:
      Log.d("AppCompatPopupWindow", "Exception while installing workaround OnScrollChangedListener", localException);
    }
    PopupWindowCompat.setOverlapAnchor(this, bool);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:54,代码来源:AppCompatPopupWindow.java


注:本文中的android.support.v4.widget.PopupWindowCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。