本文整理匯總了Java中android.widget.PopupMenu類的典型用法代碼示例。如果您正苦於以下問題:Java PopupMenu類的具體用法?Java PopupMenu怎麽用?Java PopupMenu使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PopupMenu類屬於android.widget包,在下文中一共展示了PopupMenu類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setListItemLongClick
import android.widget.PopupMenu; //導入依賴的package包/類
private void setListItemLongClick(ListView listView) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int pos, long id) {
PopupMenu popup = new PopupMenu(TaskActivity.this, view);
popup.inflate(R.menu.task_item);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
TaskEntity task = (TaskEntity) mAdapter.getItem(pos - 1);
handleTaskPopupAction(item, task);
return true;
}
});
popup.show();
return true;
}
});
}
示例2: showMenu
import android.widget.PopupMenu; //導入依賴的package包/類
public void showMenu(View v) {
PopupMenu popup = new PopupMenu(context, v);
popup.setOnMenuItemClickListener(this);
popup.inflate(R.menu.playlist_popup_menu);
// Force icons to show
Object menuHelper;
Class[] argTypes;
try {
Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup");
fMenuHelper.setAccessible(true);
menuHelper = fMenuHelper.get(popup);
argTypes = new Class[]{boolean.class};
menuHelper.getClass().getDeclaredMethod("setForceShowIcon", argTypes).invoke(menuHelper, true);
} catch (Exception e) {
e.printStackTrace();
popup.show();
return;
}
popup.show();
}
示例3: showMenu
import android.widget.PopupMenu; //導入依賴的package包/類
public void showMenu(View view, Project project) {
final PopupMenu pm = new PopupMenu(getContext(), view);
pm.inflate(R.menu.menu_project);
if(project.getState() == State.OPEN) {
pm.getMenu().add(0, R.id.menu_toggle_project_state, 0, R.string.menu_close_project);
} else {
pm.getMenu().add(0, R.id.menu_toggle_project_state, 0, R.string.menu_reopen_project);
}
pm.setOnMenuItemClickListener(item -> {
switch(item.getItemId()) {
case R.id.menu_toggle_project_state:
toggleProjectState(project);
break;
case R.id.menu_edit_project:
editProject(project, view);
break;
case R.id.menu_delete_project:
deleteProject(project);
break;
}
return true;
});
pm.show();
}
示例4: openMenu
import android.widget.PopupMenu; //導入依賴的package包/類
public void openMenu(View view, final Issue issue) {
final PopupMenu menu = new PopupMenu(getContext(), view);
menu.inflate(R.menu.menu_issue);
menu.getMenu().add(0, R.id.menu_toggle_issue_state, Menu.NONE,
issue.isClosed() ? R.string.menu_reopen_issue : R.string.menu_close_issue
);
menu.getMenu().add(0, R.id.menu_edit_issue, Menu.NONE, getString(R.string.menu_edit_issue));
menu.setOnMenuItemClickListener(menuItem -> {
switch(menuItem.getItemId()) {
case R.id.menu_toggle_issue_state:
toggleIssueState(issue);
break;
case R.id.menu_edit_issue:
editIssue(view, issue);
break;
case R.id.menu_fullscreen:
IntentHandler.showFullScreen(getContext(), issue.getBody(),
issue.getRepoFullName(), getFragmentManager()
);
break;
}
return false;
});
menu.show();
}
示例5: popFilterMenu
import android.widget.PopupMenu; //導入依賴的package包/類
public void popFilterMenu(View rootview) {
int style = ResHelper.getStyleRes(getContext(), "BBS_PopupMenu");
Context wrapper = new ContextThemeWrapper(getContext(), style);
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(wrapper, rootview);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(PageForumThreadDetail.getMenuRes(getContext(), "bbs_popup_forumthread"), popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//only one menu item.
if (item.getItemId() == ResHelper.getIdRes(getContext(), "action_arrangebycomment")) {
orderType = ThreadListOrderType.LAST_POST;
performPullingDown(true);
} else if (item.getItemId() == ResHelper.getIdRes(getContext(), "action_arrangebypost")) {
orderType = ThreadListOrderType.CREATE_ON;
performPullingDown(true);
}
return true;
}
});
popup.show();
}
示例6: showPopup
import android.widget.PopupMenu; //導入依賴的package包/類
private void showPopup() {
PopupMenu popup = new PopupMenu(getActivity(), btn_more);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.share_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_send:
initShare(1);
break;
case R.id.menu_receive:
initShare(0);
break;
}
return true;
}
});
popup.show();
}
示例7: onLongClick
import android.widget.PopupMenu; //導入依賴的package包/類
@Override
public boolean onLongClick(View v) {
PopupMenu menu = new PopupMenu(v.getContext(), v);
menu.getMenu().add(0, CONTEXT_MENU_FILTER_ID, 0, R.string.filter_choice);
menu.getMenu().add(0, CONTEXT_MENU_COPY_ID, 0, R.string.copy_to_clipboard);
menu.setOnMenuItemClickListener(LogLineViewHolder.this);
menu.show();
return true;
}
示例8: showPopupMenu
import android.widget.PopupMenu; //導入依賴的package包/類
private void showPopupMenu(View view, final StatusRes statusRes) {
PopupMenu popupMenu = new PopupMenu(mContext, view);
if (statusRes.isIs_self()) {
popupMenu.inflate(R.menu.menu_item_status_self);
} else {
popupMenu.inflate(R.menu.menu_item_status);
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_delete:
showDeleteStatusDailog(statusRes);
break;
case R.id.action_copy:
copyStatus(statusRes);
break;
case R.id.action_share:
break;
}
return false;
}
});
popupMenu.show();
}
示例9: showToc
import android.widget.PopupMenu; //導入依賴的package包/類
protected void showToc() {
Map<String,String> tocmap = book.getToc();
PopupMenu tocmenu = new PopupMenu(this, findViewById(R.id.contents_button));
for (final String point: tocmap.keySet()) {
String text = tocmap.get(point);
MenuItem m = tocmenu.getMenu().add(text);
//Log.d("EPUB", "TOC2: " + text + ". File: " + point);
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
handleLink(point);
return true;
}
});
}
if (tocmap.size()==0) {
tocmenu.getMenu().add(R.string.no_toc_found);
}
tocmenu.show();
}
示例10: onLongClick
import android.widget.PopupMenu; //導入依賴的package包/類
@Override
public boolean onLongClick(final View v) {
PopupMenu p = new PopupMenu(this, v);
MenuItem m = p.getMenu().add("Delete");
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
list.removeView(v);
db.deleteWebSite((String)v.getTag());
return true;
}
});
p.show();
return true;
}
示例11: setForceShowIcon
import android.widget.PopupMenu; //導入依賴的package包/類
public static void setForceShowIcon(PopupMenu popupMenu) {
try {
Field[] fields = popupMenu.getClass().getDeclaredFields();
for (Field field : fields) {
if ("mPopup".equals(field.getName())) {
field.setAccessible(true);
Object menuPopupHelper = field.get(popupMenu);
Class<?> classPopupHelper = Class.forName(menuPopupHelper
.getClass().getName());
Method setForceIcons = classPopupHelper.getMethod(
"setForceShowIcon", boolean.class);
setForceIcons.invoke(menuPopupHelper, true);
break;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
示例12: showPopupMenu
import android.widget.PopupMenu; //導入依賴的package包/類
protected void showPopupMenu(View view, final int position) {
final FavoriteArticle article = (FavoriteArticle) getItem(position);
PopupMenu popup = new PopupMenu(this.context, view);
popup.getMenu().add(0, 0, 0, "取消收藏");
popup.show();
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case 0:
WebFavoriteFragment.this.deleteFavoriteArticle(article, position);
break;
}
return false;
}
});
}
示例13: onBlockMenuClick
import android.widget.PopupMenu; //導入依賴的package包/類
@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
final PopupMenu popupMenu = new PopupMenu(activity, view);
popupMenu.inflate(R.menu.blocks_context);
popupMenu.getMenu().findItem(R.id.blocks_context_browse).setVisible(Constants.ENABLE_BROWSE);
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
switch (item.getItemId()) {
case R.id.blocks_context_browse:
final String blockHash = block.getHeader().getHashAsString();
final Uri blockExplorerUri = config.getBlockExplorer();
log.info("Viewing block {} on {}", blockHash, blockExplorerUri);
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.withAppendedPath(blockExplorerUri, "block/" + blockHash)));
return true;
}
return false;
}
});
popupMenu.show();
}
示例14: pickDateButtonClick
import android.widget.PopupMenu; //導入依賴的package包/類
public void pickDateButtonClick(View view) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(CowDetailsActivity.this, pickDateButton);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.date_popup_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
popupSelectedItemId = item.getItemId();
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.setListener(CowDetailsActivity.this);
/* Bundle args = new Bundle();
args.putInt("num", num);
newFragment.setArguments(args);*/
newFragment.show(getFragmentManager(), "datePickr");
return true;
}
});
popup.show();//showing popup menu
}
示例15: onMediaClick
import android.widget.PopupMenu; //導入依賴的package包/類
private void onMediaClick(QueuedMedia item, View view) {
PopupMenu popup = new PopupMenu(this, view);
final int addCaptionId = 1;
final int removeId = 2;
popup.getMenu().add(0, addCaptionId, 0, R.string.action_set_caption);
popup.getMenu().add(0, removeId, 0, R.string.action_remove_media);
popup.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
case addCaptionId:
makeCaptionDialog(item);
break;
case removeId:
removeMediaFromQueue(item);
break;
}
return true;
});
popup.show();
}