android.support.v7.widget.PopupMenu.inflate()方法的使用及代码示例

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

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

PopupMenu.inflate介绍

暂无

代码示例

代码示例来源:origin: hidroh/materialistic

@Override
public PopupMenu inflate(@MenuRes int menuRes) {
  mSupportPopupMenu.inflate(menuRes);
  return this;
}

代码示例来源:origin: mancj/MaterialSearchBar

private void inflateMenuRequest(int menuResource, int iconResId
) {
  int menuResource1 = menuResource;
  if (menuResource1 > 0) {
    ImageView menuIcon = findViewById(R.id.mt_menu);
    if (iconResId != -1) {
      menuIconRes = iconResId;
      menuIcon.setImageResource(menuIconRes);
    }
    RelativeLayout.LayoutParams params = (LayoutParams) searchIcon.getLayoutParams();
    params.rightMargin = (int) (48 * destiny);
    searchIcon.setLayoutParams(params);
    menuIcon.setVisibility(VISIBLE);
    menuIcon.setOnClickListener(this);
    popupMenu = new PopupMenu(getContext(), menuIcon);
    popupMenu.inflate(menuResource);
    popupMenu.setGravity(Gravity.RIGHT);
  }
}

代码示例来源:origin: aa112901/remusic

popupMenu.inflate(R.menu.popmenu);
popupMenu.show();

代码示例来源:origin: k9mail/k-9

@Override
public void onClick(View view) {
  int id = view.getId();
  if (id == R.id.from) {
    onAddSenderToContacts();
  } else if (id == R.id.to || id == R.id.cc || id == R.id.bcc) {
    expand((TextView)view, ((TextView)view).getEllipsize() != null);
    layoutChanged();
  } else if (id == R.id.crypto_status_icon) {
    onCryptoClickListener.onCryptoClick();
  } else if (id == R.id.icon_single_message_options) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.setOnMenuItemClickListener(onMenuItemClickListener);
    popupMenu.inflate(R.menu.single_message_options);
    popupMenu.show();
  }
}

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: iMeiji/Toutiao

PopupMenu popupMenu = new PopupMenu(context,
    holder.iv_dots, Gravity.END, 0, R.style.MyPopupMenu);
popupMenu.inflate(R.menu.menu_share);
popupMenu.setOnMenuItemClickListener(menu -> {
  int itemId = menu.getItemId();

代码示例来源:origin: willowtreeapps/Hyperion-Android

@Override
  public void onClick(final View v) {
    PopupMenu menu = new PopupMenu(itemView.getContext(), options);
    menu.inflate(R.menu.hd_file_options);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {
        final Context context = v.getContext();
        int id = item.getItemId();
        if (id == R.id.share) {
          Intent intent = new Intent(Intent.ACTION_SEND);
          intent.setType(FileViewHolder.this.item.mimeType);
          intent.putExtra(Intent.EXTRA_STREAM, FileViewHolder.this.item.uri);
          context.startActivity(Intent.createChooser(intent, "Share file"));
          return true;
        }
        if (id == R.id.delete) {
          boolean deleted = FileViewHolder.this.item.file.delete();
          if (!deleted) {
            Toast.makeText(context, "Could not delete file.", Toast.LENGTH_LONG).show();
          }
          return true;
        }
        return false;
      }
    });
    menu.show();
  }
});

代码示例来源:origin: willowtreeapps/Hyperion-Android

private void showMenu(View anchor) {
  final Context context = anchor.getContext();
  if (popupMenu != null) {
    popupMenu.dismiss();
  }
  popupMenu = new PopupMenu(context, anchor);
  popupMenu.inflate(R.menu.hgc_menu_options);
  final Menu menu = popupMenu.getMenu();
  final MenuItem areHapticsEnabledItem = menu.findItem(R.id.menu_item_use_haptics);
  areHapticsEnabledItem.setChecked(detector.areHapticsEnabled());
  areHapticsEnabledItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      boolean areHapticsEnabled = !item.isChecked();
      item.setChecked(areHapticsEnabled);
      detector.setHapticsEnabled(areHapticsEnabled);
      return true;
    }
  });
  popupMenu.show();
}

代码示例来源:origin: ricknout/lens-launcher

@Override
  public void onClick(View view) {
    PopupMenu popupMenu = new PopupMenu(mContext, view);
    popupMenu.setOnMenuItemClickListener(AppViewHolder.this);
    popupMenu.inflate(R.menu.menu_app);
    popupMenu.show();
  }
});

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

public void showPopupMenu(View view) throws NoSuchFieldException, IllegalAccessException {
    PopupMenu popupMenu = new PopupMenu(this, view);
    //设置 PopupMenu 的显示菜单项
    popupMenu.inflate(R.menu.main);
    // popupMenu.getMenuInflater().inflate(R.menu.main, popupMenu.getMenu());//与一行没什么区别
    //默认 PopupMenu 不显示条目icon,可以通过反射来强制使其显示icon
    Field field = popupMenu.getClass().getDeclaredField("mPopup");
    field.setAccessible(true);
    MenuPopupHelper mHelper = (MenuPopupHelper) field.get(popupMenu);
    mHelper.setForceShowIcon(true);
    //设置 PopupMenu 的条目点击事件(点击后会自动dismiss)
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {
        Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        return false;
      }
    });
    //显示 PopupMenu
    popupMenu.show();
  }
}

代码示例来源:origin: jasonwyatt/Squeaky-Android

@Override
public boolean onLongClick(View view) {
  PopupMenu menu = new PopupMenu(view.getContext(), view);
  menu.inflate(R.menu.item_popup);
  menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == R.id.delete) {
        sObservable.notifyObservers(new DeleteEvent(mItem));
      }
      return false;
    }
  });
  menu.show();
  return true;
}

代码示例来源:origin: YoKeyword/SwipeBackFragment

@Override
  public void onClick(View v) {
    final PopupMenu popupMenu = new PopupMenu(getActivity(), v, GravityCompat.END);
    popupMenu.inflate(R.menu.swipe_orientation);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {
        switch (item.getItemId()) {
          case R.id.action_left:
            getSwipeBackLayout().setEdgeOrientation(SwipeBackLayout.EDGE_LEFT);
            Toast.makeText(getActivity(), "left", Toast.LENGTH_SHORT).show();
            break;
          case R.id.action_right:
            getSwipeBackLayout().setEdgeOrientation(SwipeBackLayout.EDGE_RIGHT);
            Toast.makeText(getActivity(), "right", Toast.LENGTH_SHORT).show();
            break;
          case R.id.action_all:
            getSwipeBackLayout().setEdgeOrientation(SwipeBackLayout.EDGE_ALL);
            Toast.makeText(getActivity(), "all", Toast.LENGTH_SHORT).show();
            break;
        }
        popupMenu.dismiss();
        return true;
      }
    });
    popupMenu.show();
  }
});

代码示例来源:origin: Light-Team/ModPE-IDE-Source

/**
   * Отображение всплывающего меню вместе с иконкой.
   * @param context - контекст для показа.
   * @param view - View по которому было нажатие.
   * @param menuRes - меню которое будет открыто.
   * @param listener - слушатель для определения нажатий.
   */
  @SuppressLint("RestrictedApi")
  public static void forceShow(Context context, View view,
                 int menuRes, PopupMenu.OnMenuItemClickListener listener) {
    ContextThemeWrapper wrapper =
        new ContextThemeWrapper(context, R.style.Theme_Platform_PopupMenu); //Светлая тема
    PopupMenu menu = new PopupMenu(wrapper, view);
    menu.inflate(menuRes);
    menu.setOnMenuItemClickListener(listener);
    MenuPopupHelper menuHelper = new MenuPopupHelper(wrapper, (MenuBuilder) menu.getMenu(), view);
    menuHelper.setForceShowIcon(true);
    menuHelper.show();
  }
}

相关文章