android.view.MenuItem类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(141)

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

暂无

代码示例

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case R.id.viewGithub: {
      Intent i = new Intent(Intent.ACTION_VIEW);
      i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java"));
      startActivity(i);
      break;
    }
  }
  return true;
}

代码示例来源:origin: EverythingMe/overscroll-decor

@Override
  public boolean onMenuItemClick(MenuItem item) {
    detachMenuItem.setVisible(true);
    attachMenuItem.setVisible(false);
    initHorizontalRecyclerView((RecyclerView) getView().findViewById(R.id.horizontal_recycler_view));
    initVerticalRecyclerView((RecyclerView) getView().findViewById(R.id.vertical_recycler_view));
    return true;
  }
});

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
 inflater.inflate(R.menu.actions, menu);
 if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT) {
  menu.findItem(R.id.open).setEnabled(true);
 }
 MenuItem checkable=menu.findItem(WORD_COUNT_MENU_IDS[wordCount-4]);
 if (checkable!=null) {
  checkable.setChecked(true);
 }
 super.onCreateOptionsMenu(menu, inflater);
}

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

@Override
public void onPrepareOptionsMenu(Menu menu) {
  MenuItem pauseOnScrollItem = menu.findItem(R.id.item_pause_on_scroll);
  pauseOnScrollItem.setVisible(true);
  pauseOnScrollItem.setChecked(pauseOnScroll);
  MenuItem pauseOnFlingItem = menu.findItem(R.id.item_pause_on_fling);
  pauseOnFlingItem.setVisible(true);
  pauseOnFlingItem.setChecked(pauseOnFling);
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void updateBookmarkButtons() {
    if (playlistBookmarkButton == null || activity == null) return;

    final int iconAttr = playlistEntity == null ?
        R.attr.ic_playlist_add : R.attr.ic_playlist_check;

    final int titleRes = playlistEntity == null ?
        R.string.bookmark_playlist : R.string.unbookmark_playlist;

    playlistBookmarkButton.setIcon(ThemeHelper.resolveResourceIdFromAttr(activity, iconAttr));
    playlistBookmarkButton.setTitle(titleRes);
  }
}

代码示例来源:origin: naman14/Timber

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  if (action.equals(Constants.NAVIGATE_PLAYLIST_USERCREATED)) {
    menu.findItem(R.id.action_delete_playlist).setVisible(true);
    menu.findItem(R.id.action_clear_auto_playlist).setVisible(false);
  } else {
    menu.findItem(R.id.action_delete_playlist).setVisible(false);
    menu.findItem(R.id.action_clear_auto_playlist).setTitle("Clear " + playlistname.getText().toString());
  }
  return super.onPrepareOptionsMenu(menu);
}

代码示例来源:origin: huangweicai/OkLibDemo

@Override
public void run() {
  int id = item.getItemId();
  if (id == R.id.my_collect) {
    Intent intent = new Intent(context, CollectActivity.class);
    startActivity(intent);
  } else if (id == R.id.check_update) {
    final View view = ((Activity)context).getLayoutInflater().inflate(R.layout.dialog_more, null);
    final ImageView iv_reward = view.findViewById(R.id.iv_reward);
    iv_reward.setImageResource(R.drawable.xingqiu_qrcode_icon);
    AlertDialog dialog = new AlertDialog.Builder(context)
    dialog.show();
  } else if (id == R.id.reward) {
    final View view = ((Activity)context).getLayoutInflater().inflate(R.layout.dialog_more, null);
    final ImageView iv_reward = view.findViewById(R.id.iv_reward);
    iv_reward.setImageResource(R.drawable.lantian_reward_icon);
    final TextView tv_title = view.findViewById(R.id.tv_title);
    tv_title.setText("微信扫一扫打赏\n在“技术微讯”点击内推圈菜单栏加入内推圈");
    AlertDialog dialog = new AlertDialog.Builder(context)
        .setView(view)

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

@Override
protected void onBindViewHolder(@NonNull final NewsArticleImgViewBinder.ViewHolder holder, @NonNull final MultiNewsArticleDataBean item) {
  final Context context = holder.itemView.getContext();
    holder.tv_title.setText(tv_title);
    holder.tv_title.setTextSize(SettingUtil.getInstance().getTextSize());
    holder.tv_abstract.setText(tv_abstract);
    holder.tv_extra.setText(tv_source + " - " + tv_comment_count + " - " + tv_datetime);
    holder.iv_dots.setOnClickListener(view -> {
      popupMenu.inflate(R.menu.menu_share);
      popupMenu.setOnMenuItemClickListener(menu -> {
        int itemId = menu.getItemId();
        if (itemId == R.id.action_share) {
          IntentAction.send(context, item.getTitle() + "\n" + item.getShare_url());

代码示例来源:origin: ac-pm/Inspeckage

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
int id = item.getItemId();
  TextView txtAppSelected = (TextView) findViewById(R.id.txtAppSelected);
  if(txtAppSelected!=null) {
    txtAppSelected.setText("... ");
  Intent sendIntent = new Intent();
  sendIntent.setAction(Intent.ACTION_SEND);
  sendIntent.putExtra(Intent.EXTRA_TEXT, "https://github.com/ac-pm/Inspeckage");
  sendIntent.setType("text/plain");
  startActivity(sendIntent);

代码示例来源:origin: gabm/TapAndTurn

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  //noinspection SimplifiableIfStatement
  if (id == R.id.action_info) {
    LayoutInflater factory = LayoutInflater.from( this );
    View titleView = factory.inflate(R.layout.info_screen_header, null);
    AlertDialog.Builder adb = new AlertDialog.Builder( this )
        .setCustomTitle(titleView)
        .setPositiveButton( "Ok", null );
    View tvs = factory.inflate( R.layout.info_screen, null );
    if( tvs != null ) {
      adb.setView( tvs );
      TextView tv = (TextView)tvs.findViewById(R.id.text_view);
      tv.setText(renderHTML(R.string.about_text, getPackageVersion()));
      tv.setMovementMethod(LinkMovementMethod.getInstance());
    } else
      adb.setMessage( "" );
    adb.create().show();
    return true;
  }
  return super.onOptionsItemSelected(item);
}

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

convertView = inflater.inflate(R.layout.custom_row_stack, null);
    .findViewById(R.id.row_textView1);
TextView tv2 = (TextView) convertView
    .findViewById(R.id.row_install_textView1);
ImageView imageIcon = (ImageView) convertView
    .findViewById(R.id.row_imageView1);
ImageView imageClick = (ImageView) convertView
    .findViewById(R.id.row_click_imageView1);
  tv1.setText(" List Item "+ " : " + position);
  imageClick.setOnClickListener(new OnClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.install:

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

setContentView(R.layout.activity_main);
final Intent intent = new Intent(this, ListDialog.class);
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
int id = item.getItemId();

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

private void bindActions(final VH holder, final Item item) {
  if (item.isDead() || item.isDeleted()) {
    holder.mMoreButton.setVisibility(View.INVISIBLE);
    return;
  holder.mMoreButton.setVisibility(View.VISIBLE);
  holder.mMoreButton.setOnClickListener(v ->
    mPopupMenu.create(mContext, holder.mMoreButton, Gravity.NO_GRAVITY)
      .inflate(R.menu.menu_contextual_comment)
      .setOnMenuItemClickListener(menuItem -> {
        if (menuItem.getItemId() == R.id.menu_contextual_vote) {
          vote(item);
          return true;
        if (menuItem.getItemId() == R.id.menu_contextual_comment) {
          mContext.startActivity(new Intent(mContext, ComposeActivity.class)
              .putExtra(ComposeActivity.EXTRA_PARENT_ID, item.getId())
              .putExtra(ComposeActivity.EXTRA_PARENT_TEXT, item.getText()));
          return true;
        if (menuItem.getItemId() == R.id.menu_contextual_share) {
          AppUtils.share(mContext,
              item.isStoryType() ? item.getDisplayedTitle() : null,

代码示例来源:origin: MCMrARM/revolution-irc

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == android.R.id.home) {
    onBackPressed();
    return true;
  }
  if (item.getItemId() == R.id.action_rename) {
    View view = LayoutInflater.from(this)
        .inflate(R.layout.dialog_edit_text, null);
    EditText text = view.findViewById(R.id.edit_text);
    text.setText(getThemeInfo().name);
    new AlertDialog.Builder(this)
        .setTitle(R.string.action_rename)
        .setView(view)
        .setPositiveButton(R.string.action_ok, (dialog1, which) -> {
          getThemeInfo().name = text.getText().toString();
          notifyThemeNameChanged();
        })
        .setNegativeButton(R.string.action_cancel, null)
        .show();
    return true;
  }
  return super.onOptionsItemSelected(item);
}

代码示例来源:origin: iZeroer/Daily

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  int id = item.getItemId();
  if (id == android.R.id.home) {
    onBackPressed();
  } else if (id == R.id.action_more) {
    final BottomSheetDialog dialog = new BottomSheetDialog(this);
    final View view = getLayoutInflater().inflate(R.layout.menu_more_actions_sheet, null);
    view.findViewById(R.id.layout_open_in_browser).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        dialog.dismiss();
        openByBrowser();
      }
    });
    view.findViewById(R.id.layout_copy_link).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        dialog.dismiss();
        copyLink();
      }
    });
    dialog.setContentView(view);
    dialog.show();
  }
  return true;
  //return super.onOptionsItemSelected(item);
}

代码示例来源:origin: rmtheis/android-ocr

@Override
public boolean onContextItemSelected(MenuItem item) {
 ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
 switch (item.getItemId()) {
   clipboardManager.setText(ocrResultView.getText());
  if (clipboardManager.hasText()) {
   Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);
   Intent shareRecognizedTextIntent = new Intent(android.content.Intent.ACTION_SEND);
   shareRecognizedTextIntent.setType("text/plain");
   shareRecognizedTextIntent.putExtra(android.content.Intent.EXTRA_TEXT, ocrResultView.getText());
   startActivity(Intent.createChooser(shareRecognizedTextIntent, "Share via"));
   return true;
 case OPTIONS_COPY_TRANSLATED_TEXT_ID:
   clipboardManager.setText(translationView.getText());
  if (clipboardManager.hasText()) {
   Toast toast = Toast.makeText(this, "Text copied.", Toast.LENGTH_LONG);

代码示例来源:origin: dsolonenko/financisto

@Override
public LocalViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  View view = LayoutInflater.from(context).inflate(R.layout.generic_list_item, parent, false);
  view.setOnClickListener(clickedView -> {
    final PopupMenu popupMenu = new PopupMenu(context, clickedView);
    int i = 0;
    for (MenuItemInfo m : createContextMenus()) {
      if (m.enabled) {
        popupMenu.getMenu().add(0, m.menuId, i++, m.titleId);
      }
    }
    popupMenu.setOnMenuItemClickListener(item -> onItemAction(item.getItemId(), clickedView));
    popupMenu.show();
  });
  return new LocalViewHolder(view);
}

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

public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu, menu);

  return super.onCreateOptionsMenu(menu);
}

public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) 
  {
    case R.id.setting: 
      startActivity(new Intent(this,Settingpage.class));
      Toast.makeText(this, "setting clicked", Toast.LENGTH_LONG).show();
      break;
  }
  return true;
}

代码示例来源:origin: andriydruk/BonjourBrowser

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  //noinspection SimplifiableIfStatement
  if (id == R.id.action_add) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_add_txt_records, null);
    final TextView keyTextView = view.findViewById(R.id.key);
    final TextView valueTextView = view.findViewById(R.id.value);
    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setMessage("Add TXT record")
        .setView(view)
        .setPositiveButton(android.R.string.ok, (dialog, id1) -> {
          mRecords.put(keyTextView.getText().toString(), valueTextView.getText().toString());
          adapter.swapTXTRecords(mRecords);
          adapter.notifyDataSetChanged();
        })
        .setNegativeButton(android.R.string.cancel, (dialog, id1) -> {
        });
    builder.create().show();
    return true;
  }
  return super.onOptionsItemSelected(item);
}

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

switch (item.getItemId()) {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.your_menu, menu);
  mSearchbar = (MenuItem) menu.findItem(R.id.searchIcon);
  View actionview = mSearchbar.getActionView();
  mEtSearchbar = ((AutoCompleteTextView) actionview
      .findViewById(R.id.search_editText));
  final ImageView searchImage = ((ImageView) actionview
      .findViewById(R.id.search_image));
  searchImage.setOnClickListener(new View.OnClickListener() {
      intent.putExtra("search_string", s);
      startActivity(intent);

相关文章