本文整理汇总了Java中android.support.v7.widget.PopupMenu.getMenu方法的典型用法代码示例。如果您正苦于以下问题:Java PopupMenu.getMenu方法的具体用法?Java PopupMenu.getMenu怎么用?Java PopupMenu.getMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.PopupMenu
的用法示例。
在下文中一共展示了PopupMenu.getMenu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: smoothScrollToUserSelectedPosition
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
public static void smoothScrollToUserSelectedPosition(final DiscreteScrollView scrollView, View anchor) {
PopupMenu popupMenu = new PopupMenu(scrollView.getContext(), anchor);
Menu menu = popupMenu.getMenu();
final RecyclerView.Adapter adapter = scrollView.getAdapter();
int itemCount = (adapter instanceof InfiniteScrollAdapter) ?
((InfiniteScrollAdapter) adapter).getRealItemCount() :
adapter.getItemCount();
for (int i = 0; i < itemCount; i++) {
menu.add(String.valueOf(i + 1));
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int destination = Integer.parseInt(String.valueOf(item.getTitle())) - 1;
if (adapter instanceof InfiniteScrollAdapter) {
destination = ((InfiniteScrollAdapter) adapter).getClosestPosition(destination);
}
scrollView.smoothScrollToPosition(destination);
return true;
}
});
popupMenu.show();
}
示例2: initPopupMenu
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
private void initPopupMenu() {
mPopupMenu = new PopupMenu(this, mImageButton_Ellipsis);
mMenu = mPopupMenu.getMenu();
// 通过XML文件添加菜单项
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.popupmenu, mMenu);
mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
/* case R.id.onekey:
showMessage("功能研发中...");
break;*/
case R.id.addbox:
//合箱发货
boxPopupMenuClick();
break;
default:
break;
}
return false;
}
});
}
示例3: showPopupMenu
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
public void showPopupMenu(View view) {
//参数View 是设置当前菜单显示的相对于View组件位置,具体位置系统会处理
PopupMenu popupMenu = new PopupMenu(this, view, Gravity.RIGHT,R.attr.popupMenuStyle,R.style.PopUpMenuStyle);
//加载menu布局
Menu menu=popupMenu.getMenu();
String[] spinnerArray = getResources().getStringArray(SPINNER_ARRAY);
int i=0;
for (i=0;i<spinnerArray.length;i++) {
menu.add(0,i,i,spinnerArray[i]);
}
menu.add(0,i,i,R.string.select_cancel);
//设置menu中的item点击事件
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (mAppAdapter==null){
return false;
}
int id = item.getItemId();
if (id<spinnerArray.length){
for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
app.selection=id;
}
mAppAdapter.notifyDataSetChanged();
refreshMenu(true);
}else {
unSelectAll();
refreshMenu(false);
}
UrlCountUtil.onEvent(UrlCountUtil.STATUS_WL_SELECTION,id+"");
return true;
}
});
popupMenu.show();
}
示例4: parseMenu
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
public static void parseMenu(Context context, @MenuRes int menuRes, List<MenuEntry> menuEntryList){
PopupMenu p = new PopupMenu(context, null);
Menu menu = p.getMenu();
new MenuInflater(context).inflate(menuRes, menu);
for (int i = 0; i < menu.size(); i++) {
android.view.MenuItem item = menu.getItem(i);
menuEntryList.add(new MenuEntry(item.getTitle().toString(), item.getIcon(), item.getItemId()));
}
}
示例5: showCategoriesPopupMenu
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
private void showCategoriesPopupMenu(final View view) {
final String allCategories = getString(R.string.all_categories);
final PopupMenu popupMenu =
new PopupMenu(this, view, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
final String title = String.valueOf(item.getTitle());
getFeedSubscriptionsFragment().changeSelectedCategory(title);
return true;
}
});
final Menu menu = popupMenu.getMenu();
menu.add(allCategories);
final Set<String> categories = SharedPrefUtils.getFeedMetaDataCategories(this);
for (final String category : categories) {
menu.add(category);
}
popupMenu.setGravity(Gravity.TOP);
popupMenu.show();
}
示例6: setQuality
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override public void setQuality(View v) {
PopupMenu popup = new PopupMenu(activity, v);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override public boolean onMenuItemClick(MenuItem item) {
player.setSelectedTrack(0, (item.getItemId() - 1));
return false;
}
});
ArrayList<Integer> formats = new ArrayList<>();
Menu menu = popup.getMenu();
menu.add(Menu.NONE, 0, 0, "Bitrate");
for (int i = 0; i < player.getTrackCount(0); i++) {
MediaFormat format = player.getTrackFormat(0, i);
if (MimeTypes.isVideo(format.mimeType)) {
Log.e("dsa", format.bitrate + "");
if (format.adaptive) {
menu.add(1, (i + 1), (i + 1), "Auto");
} else {
if (!formats.contains(format.bitrate)) {
menu.add(1, (i + 1), (i + 1), (format.bitrate) / 1000 + " kbps");
formats.add(format.bitrate);
}
}
}
}
menu.setGroupCheckable(1, true, true);
menu.findItem((player.getSelectedTrack(0) + 1)).setChecked(true);
popup.show();
}
示例7: showVisibilityMenu
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
public void showVisibilityMenu(View v) {
final ImageButton rV = (ImageButton) v;
PopupMenu popup = new PopupMenu(SendToot.this, v);
popup.getMenuInflater().inflate(R.menu.set_visibility_menu, popup.getMenu());
popup.setOnMenuItemClickListener((MenuItem item) -> {
Log.d(TAG, String.valueOf(item.getItemId()));
rV.setImageDrawable(item.getIcon());
switch(item.getItemId()) {
case R.id.visibility_public:
ToastMaker.buildToasty(this, "Your post will appear in public timelines").show();
break;
case R.id.visibility_unlisted:
ToastMaker.buildToasty(this, "Your post will not appear public timelines").show();
break;
case R.id.visibility_private:
ToastMaker.buildToasty(this, "Your post will appear to followers only").show();
break;
case R.id.visibility_direct:
ToastMaker.buildToasty(this, "Your post will appear to mentioned user only").show();
break;
default:
Log.d(TAG, "memes");
}
return true;
});
MenuPopupHelper menuHelper = new MenuPopupHelper(SendToot.this, (MenuBuilder) popup.getMenu(), v);
menuHelper.setForceShowIcon(true);
menuHelper.show();
}
示例8: onOptionsItemSelected
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.filter) {
PopupMenu popup = new PopupMenu(this, findViewById(item.getItemId()));
final Menu menu = popup.getMenu();
if (qualities != null && qualities.size() > 0)
for (int i = 0; i < qualities.size(); i++) {
Element quality = qualities.get(i);
menu.add(2, i, 0, quality.getQuality());
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
qualityPosition = menuItem.getItemId();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(TwitchPlayActivity.this);
preferences.edit().putInt("player_default_quality", qualityPosition).commit();
setStreamQuality();
return true;
}
});
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu popupMenu) {
toggleHideyBar();
}
});
popup.show();
return true;
}
return super.onOptionsItemSelected(item);
}
示例9: onOptionsItemSelected
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.filter:
PopupMenu popup = new PopupMenu(getActivity(), getActivity().findViewById(item.getItemId()));
final Menu menu = popup.getMenu();
String[] itemTypes = getResources().getStringArray(R.array.item_types);
for (int i = 0; i < itemTypes.length; i++) {
menu.add(2, i, 0, itemTypes[i]);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getItemId() == 0) {
item.setTitle(R.string.filter);
mSelectedFilter = null;
} else {
item.setTitle(menuItem.getTitle());
mSelectedFilter = ResourceUtils.getItemType(menuItem.getItemId());
}
loadItems();
return true;
}
});
popup.show();
return true;
/* case R.id.about:
startActivity(new Intent(getActivity(), AboutActivity.class));
return true;
case R.id.locale:
showLanguageDialog();
return true;
case R.id.new_version:
UpdateUtils.checkNewVersion(getActivity(), true);
return true;*/
}
return super.onOptionsItemSelected(item);
}
示例10: onOptionsItemSelected
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.filter) {
PopupMenu popup = new PopupMenu(this, findViewById(item.getItemId()));
final Menu menu = popup.getMenu();
String[] itemTypes = getResources().getStringArray(R.array.item_types);
for (int i = 0; i < itemTypes.length; i++) {
menu.add(2, i, 0, itemTypes[i]);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getItemId() == 0) {
item.setTitle(R.string.filter);
selectedFilter = null;
} else {
item.setTitle(menuItem.getTitle());
selectedFilter = ResourceUtils.getItemType(menuItem.getItemId());
}
loadItems();
return true;
}
});
popup.show();
return true;
}
return super.onOptionsItemSelected(item);
}
示例11: onOptionsItemSelected
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == REFRESH) {
loadCosmeticItemsFromWeb();
return true;
} else if (item.getItemId() == R.id.filter) {
PopupMenu popup = new PopupMenu(getActivity(), getActivity().findViewById(item.getItemId()));
final Menu menu = popup.getMenu();
String[] itemTypes = getResources().getStringArray(R.array.cosmetic_items_filter);
for (int i = 0; i < itemTypes.length; i++) {
menu.add(2, i, 0, itemTypes[i]);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getItemId() == 0) {
item.setTitle(R.string.filter);
filter = null;
} else {
item.setTitle(menuItem.getTitle());
filter = ResourceUtils.getCosmeticItemType(menuItem.getItemId());
}
if (adapter != null) {
adapter.setFilterValue(filter);
adapter.getFilter().filter(searchQuery != null ? searchQuery : "");
}
return true;
}
});
popup.show();
return true;
} else {
return false;
}
}
示例12: onOptionsItemSelected
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.filter) {
PopupMenu popup = new PopupMenu(this, findViewById(item.getItemId()));
final Menu menu = popup.getMenu();
String[] heroRoles = getResources().getStringArray(R.array.hero_roles);
for (int i = 0; i < heroRoles.length; i++) {
menu.add(2, i, 0, heroRoles[i]);
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getItemId() == 0) {
item.setTitle(R.string.filter);
selectedFilter = null;
} else {
item.setTitle(menuItem.getTitle());
selectedFilter = ResourceUtils.getHeroRole(menuItem.getItemId());
}
loadHeroesForGridView();
return true;
}
});
popup.show();
return true;
} else if (item.getItemId() == R.id.ready) {
Intent intent = new Intent();
intent.putIntegerArrayListExtra("enemies", enemies);
intent.putIntegerArrayListExtra("allies", allies);
setResult(RESULT_OK, intent);
finish();
}
return super.onOptionsItemSelected(item);
}
示例13: onClick
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public void onClick(View view) {
final PopupMenu popupMenu = new PopupMenu(itemView.getContext(), view);
final Menu menu = popupMenu.getMenu();
popupMenu.getMenuInflater().inflate(R.menu.ss_lesson_item_menu, menu);
popupMenu.setOnMenuItemClickListener(this);
popupMenu.setGravity(Gravity.END);
popupMenu.show();
}
示例14: NavigationAdapter
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
public NavigationAdapter(final AppCompatActivity activity, final int menuRes) {
super(activity.getSupportFragmentManager());
final PopupMenu popupMenu = new PopupMenu(activity, activity.findViewById(android.R.id.content));
final Menu menu = popupMenu.getMenu();
activity.getMenuInflater().inflate(menuRes, menu);
fragments.clear();
fragments.add(new BrowseFragment());
fragments.add(new RecentFragment());
fragments.add(new ScanFragment());
fragments.add(new FavoritesFragment());
fragments.add(new MeFragment());
}
示例15: onPopUpMenuClicked
import android.support.v7.widget.PopupMenu; //导入方法依赖的package包/类
@Override
public void onPopUpMenuClicked(View anchor, final int position) {
final Track track = trackList.get(position);
final PopupMenu trackMenu = new PopupMenu(getActivity(), anchor);
final Menu menu = trackMenu.getMenu();
if (track.isDownloaded() && track.getFile().exists()) {
//Build R.menu.menu_track_downloaded
menu.add(position, R.id.miPlay, 1, R.string.Play);
menu.add(position, R.id.miShareFile, 2, R.string.Share_file);
menu.add(position, R.id.miShareURL, 3, R.string.Share_URL);
menu.add(position, R.id.miDownload, 4, R.string.Download_again);
menu.add(position, R.id.miOpenTrackDirectory, 5, R.string.Open_track_directory);
menu.add(position, R.id.miRemove, 6, R.string.Remove);
} else {
//Build R.menu.menu_track_not_downloaded
menu.add(position, R.id.miDownload, 1, R.string.Download);
menu.add(position, R.id.miShareURL, 2, R.string.Share_URL);
menu.add(position, R.id.miRemove, 3, R.string.Remove);
}
trackMenu.setOnMenuItemClickListener(this);
trackMenu.show();
}