try { String keyCommand = "input keyevent " + KeyEvent.KEYCODE_MENU; Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(keyCommand); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
上面这个是 模拟菜单按钮 按下
模拟其它按键只需将KeyEvent.KEYCODE_MENU替换成其它键值
如果 是 打开 MENU 也可以直接使用openOptionsMenu();
iv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub openOptionsMenu(); } });