本文整理汇总了Java中android.support.v7.widget.PopupMenu类的典型用法代码示例。如果您正苦于以下问题:Java PopupMenu类的具体用法?Java PopupMenu怎么用?Java PopupMenu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PopupMenu类属于android.support.v7.widget包,在下文中一共展示了PopupMenu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showFilteringPopUpMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
@Override
public void showFilteringPopUpMenu() {
PopupMenu popup = new PopupMenu(getContext(), getActivity().findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.active:
mPresenter.setFiltering(TasksFilterType.ACTIVE_TASKS);
break;
case R.id.completed:
mPresenter.setFiltering(TasksFilterType.COMPLETED_TASKS);
break;
default:
mPresenter.setFiltering(TasksFilterType.ALL_TASKS);
break;
}
mPresenter.loadTasks(false);
return true;
});
popup.show();
}
示例2: 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();
}
示例3: popupMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
public static void popupMenu(final Activity context, View v,final int position) {
rootview = v;
final PopupMenu popup = new PopupMenu(context, v);
popup.getMenuInflater().inflate(R.menu.list_popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.setAsNext:
setAsNext(context,position);
return true;
case delete:
deleteFile(context,Data.getData(position));
return true;
case R.id.setAsRingtone:
menu_util.setAsRingtone(context, position);
return true;
case R.id.musicInfo:
showMusicInfo(context,position);
return true;
}
return true;
}
});
popup.show(); //showing popup menu
}
示例4: 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;
}
});
}
示例5: showMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
private void showMenu(View v, final int position, final Connection connection) {
final PopupMenu popupMenu = new PopupMenu(mContext, v);
popupMenu.inflate(R.menu.menu_connection_item);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit:
ConnectionActivity.openActivity(mContext, connection);
return true;
case R.id.action_delete:
MQTTManager.getInstance().removeClient(connection.getId());
RealmHelper.getInstance().deleteTopic(Subscription.class,connection.getId());
RealmHelper.getInstance().delete(connection);
notifyItemRemoved(position);
notifyItemRangeChanged(position, getItemCount());
return true;
default:
return false;
}
}
});
popupMenu.show();
}
示例6: showMoreMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
private void showMoreMenu(View view, final int position) {
PopupMenu popup = new PopupMenu(mContext, view);
popup.getMenuInflater()
.inflate(R.menu.popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.edit:
mOnItemClickListener.onEditClick(position);
break;
case R.id.delete:
mOnItemClickListener.onDeleteClick(position);
break;
}
return true;
}
});
popup.show();
}
示例7: showMoreMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
private void showMoreMenu(View view, final int position) {
PopupMenu popup = new PopupMenu(mContext, view);
popup.getMenuInflater()
.inflate(R.menu.popup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.edit:
mOnNoteItemClickListener.onEditClick(position);
break;
case R.id.delete:
mOnNoteItemClickListener.onDeleteClick(position);
break;
}
return true;
}
});
popup.show();
}
示例8: showFilteringPopupMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
public void showFilteringPopupMenu() {
PopupMenu popup = new PopupMenu(this.getContext(),
MainActivity.get(this.getContext()).findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.active:
tasksPresenter.setFiltering(TasksFilterType.ACTIVE_TASKS);
break;
case R.id.completed:
tasksPresenter.setFiltering(TasksFilterType.COMPLETED_TASKS);
break;
default:
tasksPresenter.setFiltering(TasksFilterType.ALL_TASKS);
break;
}
//loadTasks(false); // reactive data source ftw
return true;
});
popup.show();
}
示例9: onMoreButtonClicked
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
public void onMoreButtonClicked(final BookInfo bookInfo, View v) {
PopupMenu popup = new PopupMenu(context, v);
popup.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.book_overflow_delete_book:
DialogFragment confirmBatchDownloadDialogFragment = new ConfirmBookDeleteDialogFragment();
Bundle confirmDeleteDialogFragmentBundle = new Bundle();
confirmDeleteDialogFragmentBundle.putInt(ConfirmBookDeleteDialogFragment.KEY_NUMBER_OF_BOOKS_TO_DELETE, 1);
confirmDeleteDialogFragmentBundle.putInt(BooksInformationDBContract.BookInformationEntery.COLUMN_NAME_ID, bookInfo.getBookId());
confirmDeleteDialogFragmentBundle.putString(BooksInformationDBContract.BookInformationEntery.COLUMN_NAME_TITLE, bookInfo.getName());
confirmBatchDownloadDialogFragment.setArguments(confirmDeleteDialogFragmentBundle);
confirmBatchDownloadDialogFragment.show(context.getSupportFragmentManager(), "ConfirmBookDeleteDialogFragment");
return true;
default:
return false;
}
});
popup.inflate(R.menu.book_card_overflow);
if (bookInfo.getDownloadStatus() < DownloadsConstants.STATUS_DOWNLOAD_COMPLETED) {
popup.getMenu().removeItem(R.id.book_overflow_delete_book);
}
popup.show();
}
示例10: showFilteringPopupMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
public void showFilteringPopupMenu() {
PopupMenu popup = new PopupMenu(this.getContext(), MainActivity.get(this.getContext()).findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.active:
tasksPresenter.setFiltering(TasksFilterType.ACTIVE_TASKS);
break;
case R.id.completed:
tasksPresenter.setFiltering(TasksFilterType.COMPLETED_TASKS);
break;
default:
tasksPresenter.setFiltering(TasksFilterType.ALL_TASKS);
break;
}
//loadTasks(false); // reactive data source ftw
return true;
});
popup.show();
}
示例11: showFilteringPopupMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
public void showFilteringPopupMenu() {
PopupMenu popup = new PopupMenu(getContext(), MainActivity.get(getContext()).findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.active:
tasksPresenter.setFiltering(TasksFilterType.ACTIVE_TASKS);
break;
case R.id.completed:
tasksPresenter.setFiltering(TasksFilterType.COMPLETED_TASKS);
break;
default:
tasksPresenter.setFiltering(TasksFilterType.ALL_TASKS);
break;
}
//loadTasks(false); // reactive data source ftw
return true;
});
popup.show();
}
示例12: showFilteringPopUpMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
private void showFilteringPopUpMenu() {
PopupMenu popup = new PopupMenu(getContext(), getActivity().findViewById(R.id.menu_filter));
popup.getMenuInflater().inflate(R.menu.filter_tasks, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.active:
tasksViewModel.setFiltering(TasksFilterType.ACTIVE_TASKS);
break;
case R.id.completed:
tasksViewModel.setFiltering(TasksFilterType.COMPLETED_TASKS);
break;
default:
tasksViewModel.setFiltering(TasksFilterType.ALL_TASKS);
break;
}
tasksViewModel.reloadTasks();
return true;
});
popup.show();
}
示例13: showMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
/**
* Shows a contextual popup menu anchored to the supplied view. Item selections are passed to
* the presenter.
*
* @param anchor
* the view to anchor the menu to, not null
* @param item
* the LibraryItem associated with the contextual menu, not null
*/
private void showMenu(final View anchor, final LibraryItem item) {
checkNotNull(item, "item cannot be null.");
checkNotNull(anchor, "overflowButton cannot be null.");
final PopupMenu menu = new PopupMenu(getContext(), anchor);
menu.inflate(contextualMenuResourceId);
menu.show();
// Propagate menu selections back to the presenter
menu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
for (final MenuItemSelectedListener listener : menuItemSelectedListeners) {
listener.onContextualMenuItemSelected(RecyclerBodyView.this, item, menuItem);
}
return true;
}
});
}
示例14: onClick
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
@Override
public void onClick(View view) {
if (view.getId() == R.id.post_image_edit_layout) {
PopupMenu popupMenu = new PopupMenu(this, mPostImageLayoutManager.getRootLayout());
popupMenu.inflate(R.menu.insert_image);
if (TextUtils.isEmpty(mPost.getFeatureImage())) {
MenuItem removeImageItem = popupMenu.getMenu().findItem(R.id.action_image_remove);
removeImageItem.setVisible(false);
}
popupMenu.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.action_insert_image_url) {
mPostEditFragment.onInsertImageUrlClicked(getInsertImageDoneAction());
} else if (item.getItemId() == R.id.action_insert_image_upload) {
mPostEditFragment.onInsertImageUploadClicked(getInsertImageDoneAction());
} else if (item.getItemId() == R.id.action_image_remove) {
getInsertImageDoneAction().call("");
}
return true;
});
popupMenu.show();
}
}
示例15: showPopupMenu
import android.support.v7.widget.PopupMenu; //导入依赖的package包/类
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();
}