我在程序中創建了一個optionMenu,當我長時間按optionMenu 按鈕時,inputKeyboard就會出現。如何設置當長時間按optionMenu 按鈕時,不讓 input keyboard 出現?
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.settingOpt:
Intent intent = new Intent(this, SettingForm.class);
this.startActivity(intent);
break;
case R.id.reminderOpt:
Intent intentR = new Intent(this, ReminderForm.class);
this.startActivity(intentR);
break;
case R.id.helpOpt:
Intent intentH = new Intent(this, HelpForm.class);
this.startActivity(intentH);
break;
case R.id.shareOpt:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, "Name of the thing to share");
share.putExtra(Intent.EXTRA_TEXT, "www.gmail.com");
startActivity(Intent.createChooser(share, "Title of the dialog that will show up"));
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
我找到解決問題的方法,要在 Launcher2 應用中
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean handled = super.onKeyDown(keyCode, event);
// Eat the long press event so the keyboard doesn't come up.
if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
return true;
}
return handled;
}