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


Java PopupMenu.setOnDismissListener方法代码示例

本文整理汇总了Java中android.widget.PopupMenu.setOnDismissListener方法的典型用法代码示例。如果您正苦于以下问题:Java PopupMenu.setOnDismissListener方法的具体用法?Java PopupMenu.setOnDismissListener怎么用?Java PopupMenu.setOnDismissListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.PopupMenu的用法示例。


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

示例1: showPopupMenu

import android.widget.PopupMenu; //导入方法依赖的package包/类
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:29,代码来源:NativeViewHierarchyManager.java

示例2: onOptionsItemSelected

import android.widget.PopupMenu; //导入方法依赖的package包/类
/**
 * Handle event when option item selected
 *
 * @param item The clicked item
 *
 * @return true or false indicate need to handle other menu item or not
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.d(TAG, "start FmRadioActivity.onOptionsItemSelected");
    switch (item.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            break;

        case R.id.fm_channel_list:
            refreshImageButton(false);
            refreshActionMenuItem(false);
            refreshPopupMenuItem(false);
            refreshActionMenuPower(false);
            // Show favorite activity.
            enterChannelList();
            break;

        case R.id.fm_power:
            Log.d(TAG, "click fm_power menu");
            if (mIsPlaying) {
                refreshImageButton(false);
                refreshActionMenuItem(false);
                refreshPopupMenuItem(false);
                refreshActionMenuPower(false);
                exitService();
                break;
            }
            powerUpFm();
            break;

        case R.id.fm_menu:
            item.setEnabled(false);

            mPopupMenu = new PopupMenu(mContext, findViewById(R.id.fm_menu));
            Menu menu = mPopupMenu.getMenu();
            mPopupMenu.getMenuInflater().inflate(R.menu.fm_menu, menu);
            mPopupMenu.setOnMenuItemClickListener(this);
            mPopupMenu.setOnDismissListener(this);

            boolean isPlaying = mService.isPowerUp();
            if (isPlaying) {
                menu.findItem(R.id.fm_record).setEnabled(true);
                menu.findItem(R.id.fm_sound_mode).setEnabled(!mService.isBtConnected());
                menu.findItem(R.id.fm_sound_mode).setTitle(
                        mService.isSpeakerUsed() ? R.string.optmenu_earphone
                                : R.string.optmenu_speaker);
                menu.findItem(R.id.fm_search).setEnabled(true);
            }
            refreshSoundModeVisiable();
            mPopupMenu.show();
            break;

        default:
            Log.e(TAG, "Error: Invalid options menu item.");
            break;
    }
    Log.d(TAG, "end FmRadioActivity.onOptionsItemSelected");
    return super.onOptionsItemSelected(item);
}
 
开发者ID:hyperion70,项目名称:android_device_MTS_x2605,代码行数:67,代码来源:FmRadioActivity.java


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