我可以为单个活动创建一个选项菜单.但现在我想在菜单中创建一个Logout选项,该选项应该可以在App中的所有活动中使用.是否有可能为应用程序创建一次"选项"菜单?
我对intellij中的maven选项有点困惑.
你会在何时使用它们之间有什么区别?

我正在尝试在从服务启动的Activity中创建一个Options菜单,然后根据来自通过Handler传递的Service的消息更改其UI.
我按如下方式设置了"选项"菜单:
/** Menu creation and setup **/
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 0, "Speaker");
menu.add(0, 2, 0, "Mute");
return true;
}
/* Handles item selections */
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
//Do something here
return true;
case 2:
//Do something here
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
但是当我的应用程序运行时它永远不会被调用.
我遇到了一些问题,我需要使用Handler来更改屏幕上的Text,因为信息是在错误的线程上传递的,同样的问题可能是菜单没有显示的原因吗?
是这样我怎么能解决它,因为我无法覆盖处理程序中的方法
在下面的代码中我遇到了问题,self.dmenu1.bind("<Button-1>", self.branches)如果有人可以请我指出正确的方向,我将非常感激.
我期望在下拉菜单中选择一个选项,它会更改它下面的列表框内的排序.
然而实际发生的是,在我做出选择之后,我必须再次单击下拉框,然后排序生效.
这不是用户期望下拉菜单工作的方式.我已经发布了完整的代码,因为你可以看到我对这一切都很陌生,但学习这是一个很好的挑战:)
在此先感谢您的帮助.
问候,
from tkinter import *
ALL = N+S+W+E
users = ['Fred Asus','Tom Yahoo','Jessy Samsung','Jermain Sony','Nikki Nikon',
'Ian IBM','Elena Google','Rob Braun','Tammy Tonika','James Intel',
'Murphy Richards','Daniel Denon']
branchlst = {138:'Driving - St Albans', 170:'Brighton', 271:'Driving - Birmingham',
330:'Leeds', 680:'Edinburgh'}
class Application(Frame):
def __init__(self, master=None):
#initiate the primary window.
Frame.__init__(self, master)
self.master.rowconfigure(0, weight=1)
self.master.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=0)
self.rowconfigure(1, weight=0)
self.rowconfigure(2, weight=3)
self.columnconfigure(0, weight=0)
self.columnconfigure(1, weight=1)
self.columnconfigure(2, weight=1)
self.grid(sticky=ALL)
self.frameset()
def frameset(self):
#define and setup frames …Run Code Online (Sandbox Code Playgroud) 我有一个选项菜单,但不希望它在屏幕水平翻转时出现.我有以下方法来确定lanscape,但需要知道如何禁用选项菜单.
private boolean isLandscape() {
if (Configuration.ORIENTATION_LANDSCAPE == getResources().getConfiguration().orientation) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud) 我已经为我的数据库类创建了一个选项菜单.启动选项菜单后,我想点击指定按钮进行所需的活动.
但问题是,如果我点击任何选项,我会被引导到MainMenu.class.任何想法为什么会这样?
码:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
new MenuInflater(this).inflate(R.menu.optionmenu, menu);
return(super.onCreateOptionsMenu(menu));
}
public boolean onOptionsItemSelected ( MenuItem item){
switch (item.getItemId())
{
case R.id.item1:
{ Intent r=new Intent(Database.this,MainMenu.class);
startActivity(r);
}
case R.id.takesurvey:
{
Toast toast=Toast.makeText(this, "check", 2000);
toast.show();
Intent r1=new Intent(Database.this,SurveyActivity.class);
startActivity(r1);
}
case R.id.viewstats:
{ Intent r2=new Intent(Database.this,Stats.class);
startActivity(r2);
}
case R.id.changesort:
{ Intent r3=new Intent(Database.this,MainMenu.class);
startActivity(r3);
}
case R.id.menuexit:
{ Intent r4=new Intent(Database.this,MainMenu.class);
startActivity(r4);
}
}
return true;
}
Run Code Online (Sandbox Code Playgroud) android 上的操作栏(工具栏)有 3 个选项菜单。它的工作正常。但问题是当我卸载并重新安装菜单项的重复项时。标题也保持不变,没有改变。有时,如果我们关闭应用程序并重新启动它的工作正常。我完全困惑和震惊。
这是代码 MainActivity (OnCreateOptionsMenu):
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = null;
if (searchItem != null) {
searchView = (SearchView) searchItem.getActionView();
}
if (searchView != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
}
MenuItem item = menu.findItem(R.id.action_wishlist);
wishlistCount = (RelativeLayout) MenuItemCompat.getActionView(item);
wishlistCount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
setWishlistCount();
MenuItem cartitem = menu.findItem(R.id.action_cart);
cartCount = (RelativeLayout) MenuItemCompat.getActionView(cartitem);
cartCount.setOnClickListener(new View.OnClickListener() …Run Code Online (Sandbox Code Playgroud) android options-menu android-optionsmenu oncreateoptionsmenu
options-menu ×7
android ×5
handler ×1
java ×1
listbox ×1
maven ×1
menu ×1
python ×1
python-3.x ×1
tkinter ×1