android.widget.PopupWindow类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中android.widget.PopupWindow类的一些代码示例,展示了PopupWindow类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PopupWindow类的具体详情如下:
包路径:android.widget.PopupWindow
类名称:PopupWindow

PopupWindow介绍

暂无

代码示例

代码示例来源:origin: jeasonlzy/NineGridView

@Override
public void onClick(View v) {
  switch (v.getId()) {
    case R.id.favour:
      Toast.makeText(context, "赞+1", Toast.LENGTH_SHORT).show();
      if (window != null) window.dismiss();
      break;
    case R.id.comment:
      View editView = mInflater.inflate(R.layout.replay_input, null);
      editWindow = new PopupWindow(editView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      editWindow.setOutsideTouchable(true);
      editWindow.setFocusable(true);
      editWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
      EditText replyEdit = (EditText) editView.findViewById(R.id.reply);
      replyEdit.setFocusable(true);
      replyEdit.requestFocus();
      editWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
      editWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
      editWindow.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
      editWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
      if (window != null) window.dismiss();
      break;

代码示例来源:origin: jeasonlzy/NineGridView

@OnClick(R.id.more)
public void more(View view) {
  View popupView = mInflater.inflate(R.layout.popup_reply, null);
  popupView.findViewById(R.id.favour).setOnClickListener(this);
  popupView.findViewById(R.id.comment).setOnClickListener(this);
  window = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  window.setOutsideTouchable(true);
  window.setFocusable(true);
  window.setAnimationStyle(R.style.popup_more_anim);
  window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
  popupView.measure(0, 0);
  int xoff = -popupView.getMeasuredWidth();
  int yoff = -(popupView.getMeasuredHeight() + view.getHeight()) / 2;
  window.showAsDropDown(view, xoff, yoff);
}

代码示例来源:origin: arcadefire/nice-spinner

@Override
public Parcelable onSaveInstanceState() {
  Bundle bundle = new Bundle();
  bundle.putParcelable(INSTANCE_STATE, super.onSaveInstanceState());
  bundle.putInt(SELECTED_INDEX, selectedIndex);
  bundle.putBoolean(IS_ARROW_HIDDEN, isArrowHidden);
  bundle.putInt(ARROW_DRAWABLE_RES_ID, arrowDrawableResId);
  if (popupWindow != null) {
    bundle.putBoolean(IS_POPUP_SHOWING, popupWindow.isShowing());
  }
  return bundle;
}

代码示例来源:origin: pili-engineering/PLDroidPlayer

private void initFloatingWindow() {
  mWindow = new PopupWindow(mContext);
  mWindow.setFocusable(false);
  mWindow.setBackgroundDrawable(null);
  mWindow.setOutsideTouchable(true);
  mAnimStyle = android.R.style.Animation;
}

代码示例来源:origin: GitLqr/LQRWeChat

/**
 * 点击popupwindow范围以外的地方时隐藏
 *
 * @param popupWindow
 */
public static void openOutsideTouchable(PopupWindow popupWindow) {
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  popupWindow.setOutsideTouchable(true);
}

代码示例来源:origin: stackoverflow.com

PopupWindow pw;
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.weight_popup, (ViewGroup)findViewById(R.id.linlay_weight_popup));
pw = new PopupWindow(layout,LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setOutsideTouchable(true);
pw.showAsDropDown(btnSelectWeight);

代码示例来源:origin: stackoverflow.com

public void displaypopup() {

  LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
      .getSystemService(LAYOUT_INFLATER_SERVICE);
  View popupView = layoutInflater.inflate(R.layout.popup, null);
  final PopupWindow popupWindow = new PopupWindow(popupView,
      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

  Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
  btnDismiss.setOnClickListener(new Button.OnClickListener() {

    @Override
    public void onClick(View v) {
      popupWindow.dismiss();
    }
  });
  popupWindow.showAtLocation(popupView, Gravity.TOP, 0, 0);
}

代码示例来源:origin: easefun/polyv-android-sdk-2.0-demo

private void initPopupWindow() {
  popupwindow_view = LayoutInflater.from(getContext()).inflate(R.layout.polyv_popupwindow_cur_bit, null);
  popupWindow = new PopupWindow(popupwindow_view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  popupWindow.setOutsideTouchable(true);
  popupWindow.setAnimationStyle(R.style.popupwindow);
  tv_hd = (TextView) popupwindow_view.findViewById(R.id.tv_hd);
  tv_sd = (TextView) popupwindow_view.findViewById(R.id.tv_sd);
  tv_flu = (TextView) popupwindow_view.findViewById(R.id.tv_flu);
  tv_hd.setOnClickListener(this);
  tv_sd.setOnClickListener(this);
  tv_flu.setOnClickListener(this);
}

代码示例来源:origin: kalaspuffar/secure-quick-reliable-login

public void setupErrorPopupWindow(LayoutInflater layoutInflater) {
  View popupView = layoutInflater.inflate(R.layout.fragment_error_dialog, null);
  errorPopupWindow = new PopupWindow(popupView,
      ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
      false);
  txtErrorMessage = popupView.findViewById(R.id.txtErrorMessage);
  final Button btnErrorOk = popupView.findViewById(R.id.btnErrorOk);
  btnErrorOk.setOnClickListener(v -> {
    errorPopupWindow.dismiss();
  });
}

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

@Override
public void onClick(View v) {
  super.onClick(v);
  int i = v.getId();
  if (i == R.id.thumb) {
    if (jzDataSource == null || jzDataSource.urlsMap.isEmpty() || jzDataSource.getCurrentUrl() == null) {
    LayoutInflater inflater = (LayoutInflater) getContext()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.jz_layout_clarity, null);
      TextView clarityItem = (TextView) View.inflate(getContext(), R.layout.jz_layout_clarity_item, null);
      clarityItem.setText(key);
      clarityItem.setTag(j);
      layout.addView(clarityItem, j);
      clarityItem.setOnClickListener(mQualityListener);
      if (j == jzDataSource.currentUrlIndex) {
        clarityItem.setTextColor(Color.parseColor("#fff85959"));
    clarityPopWindow = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
    clarityPopWindow.setContentView(layout);
    clarityPopWindow.showAsDropDown(clarity);
    layout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
    int offsetX = clarity.getMeasuredWidth() / 3;
    int offsetY = clarity.getMeasuredHeight() / 3;
    clarityPopWindow.update(clarity, -offsetX, -offsetY, Math.round(layout.getMeasuredWidth() * 2), layout.getMeasuredHeight());
  } else if (i == R.id.retry_btn) {
    if (jzDataSource.urlsMap.isEmpty() || jzDataSource.getCurrentUrl() == null) {

代码示例来源:origin: gkasten/drrickorang

public void onButtonHelp(View view) {
  // Create a PopUpWindow with scrollable TextView
  View puLayout = this.getLayoutInflater().inflate(R.layout.report_window, null);
  PopupWindow popUp = new PopupWindow(puLayout, ViewGroup.LayoutParams.MATCH_PARENT,
      ViewGroup.LayoutParams.MATCH_PARENT, true);
  TextView helpText =
      (TextView) popUp.getContentView().findViewById(R.id.ReportInfo);
  if (view.getId() == R.id.buttonSystraceHelp || view.getId() == R.id.buttonBugreportHelp) {
    helpText.setText(getResources().getString(R.string.systraceHelp));
  } else if (view.getId() == R.id.buttonCalibrateSoundLevelHelp) {
    helpText.setText(getResources().getString(R.string.calibrateSoundLevelHelp));
  }
  // display pop up window, dismissible with back button
  popUp.showAtLocation((View) findViewById(R.id.settingsMainLayout), Gravity.TOP, 0, 0);
}

代码示例来源:origin: GitLqr/LQRWeChat

private void showPopupMenu() {
  if (mView == null) {
    mView = new FrameLayout(this);
    mView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mView.setBackgroundColor(UIUtils.getColor(R.color.white));
    TextView tv = new TextView(this);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, UIUtils.dip2Px(45));
    tv.setLayoutParams(params);
    tv.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    tv.setPadding(UIUtils.dip2Px(20), 0, 0, 0);
    tv.setTextColor(UIUtils.getColor(R.color.gray0));
    tv.setTextSize(14);
    tv.setText(UIUtils.getString(R.string.select_qr_code_from_ablum));
    mView.addView(tv);
    tv.setOnClickListener(v -> {
      mPopupWindow.dismiss();
      Intent intent = new Intent(ScanActivity.this, ImageGridActivity.class);
      startActivityForResult(intent, IMAGE_PICKER);
    });
  }
  mPopupWindow = PopupWindowUtils.getPopupWindowAtLocation(mView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, getWindow().getDecorView().getRootView(), Gravity.BOTTOM, 0, 0);
  mPopupWindow.setOnDismissListener(() -> PopupWindowUtils.makeWindowLight(ScanActivity.this));
  PopupWindowUtils.makeWindowDark(this);
}

代码示例来源:origin: stackoverflow.com

@Override
public void onClick(View view) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
  @Override
  public void onClick(View v) {
    popupWindow.dismiss();
  }});
popupWindow.showAsDropDown(view, 0, -0);

代码示例来源:origin: techery/progresshint

private void initHintPopup() {
 String popupText = null;
 if (mHintAdapter != null) {
  popupText = mHintAdapter.getHint(mSeekBar, mSeekBar.getProgress());
 }
 // init views
 LayoutInflater inflater = (LayoutInflater) mSeekBar.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 mPopupView = inflater.inflate(mPopupLayout, null);
 mPopupView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED));
 mPopupTextView = mPopupView.findViewById(android.R.id.text1);
 mPopupTextView.setText(popupText != null ? popupText : String.valueOf(mSeekBar.getProgress()));
 // init popup
 mPopup = new PopupWindow(mPopupView, WRAP_CONTENT, WRAP_CONTENT, false);
 mPopup.setAnimationStyle(mPopupAnimStyle);
}

代码示例来源:origin: zyyoona7/EasyPopup

private void initCirclePop() {
  View view = LayoutInflater.from(this).inflate(R.layout.layout_circle_comment, null);
  mCiclePop = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  mCiclePop.setAnimationStyle(R.style.RightPopAnim);
  mCiclePop.setFocusable(true);
  mCiclePop.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  mCiclePop.setOutsideTouchable(true);
}

代码示例来源:origin: LiuGuiLinAndroid/LoveWallpaper

private void initMenuWindow() {
  contentView = LayoutInflater.from(this).inflate(R.layout.pop_item_layout, null);
  tv_game = (TextView) contentView.findViewById(R.id.tv_game);
  tv_game.setOnClickListener(this);
  tv_shell = (TextView) contentView.findViewById(R.id.tv_shell);
  tv_shell.setOnClickListener(this);
  popWnd = new PopupWindow(this);
  popWnd.setContentView(contentView);
  popWnd.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  popWnd.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  popWnd.setOutsideTouchable(true);
  popWnd.setBackgroundDrawable(new BitmapDrawable());
}

代码示例来源:origin: stackoverflow.com

super.onDetachedFromWindow();
if (mPopupWindow != null)
  mPopupWindow.dismiss();
      return;
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    final View popupView = layoutInflater.inflate(R.layout.spinner_drop_down_popup, null, false);
    final LinearLayout linearLayout = (LinearLayout) popupView.findViewById(android.R.id.list);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    mPopupWindow = new PopupWindow(popupView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setBackgroundDrawable(new ColorDrawable(0));
    mPopupWindow.setFocusable(true);
    final AtomicBoolean isItemSelected = new AtomicBoolean(false);
    for (int i = 0; i < mItems.length; ++i) {
      final String item = mItems[i];
      final int position = i;
      View itemView = layoutInflater.inflate(android.R.layout.simple_list_item_1, linearLayout, false);
      itemView.setBackgroundResource(R.drawable.listview_white_selector);
      itemView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        public void onClick(final View v) {
          isItemSelected.set(true);
          mPopupWindow.dismiss();
          mSelectedItemPosition = position;
          setText(item);
      @Override

代码示例来源:origin: sdwfqin/AndroidSamples

private void showPopupWindow(int x, int y) {
  View contentView = LayoutInflater.from(LongShowPopupActivity.this).inflate(R.layout.show_as_drop_down_activity_popup, null);
  mPopWindow = new PopupWindow(contentView);
  mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  TextView tv1 = contentView.findViewById(R.id.pop_computer);
  TextView tv2 = contentView.findViewById(R.id.pop_financial);
  TextView tv3 = contentView.findViewById(R.id.pop_manage);
  tv1.setOnClickListener(this);
  tv2.setOnClickListener(this);
  tv3.setOnClickListener(this);
  View rootview = LayoutInflater.from(LongShowPopupActivity.this).inflate(R.layout.activity_long_show_popup, null);
  mPopWindow.showAtLocation(rootview, Gravity.NO_GRAVITY, x, y);
}

代码示例来源:origin: sdwfqin/AndroidSamples

private void showPopupWindow() {
  View contentView = LayoutInflater.from(PopupShowAsDropDownActivity.this).inflate(R.layout.show_as_drop_down_activity_popup, null);
  mPopWindow = new PopupWindow(contentView);
  mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  TextView tv1 = contentView.findViewById(R.id.pop_computer);
  TextView tv2 = contentView.findViewById(R.id.pop_financial);
  TextView tv3 = contentView.findViewById(R.id.pop_manage);
  tv1.setOnClickListener(this);
  tv2.setOnClickListener(this);
  tv3.setOnClickListener(this);
  mPopWindow.showAsDropDown(mMenuTv);
}

代码示例来源:origin: sdwfqin/AndroidSamples

private void showPopupWindow() {
  View contentView = LayoutInflater.from(PopupAnimActivity.this).inflate(R.layout.anim_activity_popup, null);
  mPopWindow = new BasePopupWindow(contentView);
  mPopWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
  mPopWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
  TextView tv1 = contentView.findViewById(R.id.pop_computer);
  TextView tv2 = contentView.findViewById(R.id.pop_financial);
  TextView tv3 = contentView.findViewById(R.id.pop_manage);
  tv1.setOnClickListener(this);
  tv2.setOnClickListener(this);
  tv3.setOnClickListener(this);
  mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
  mPopWindow.showAsDropDown(mMenuTv);
}

相关文章