我试图检测Android手机上的物理菜单按钮何时被按下.我虽然下面的代码可以工作,但事实并非如此.我哪里出错了?
返回的错误是'onKeyDown参数的非法修饰符; 只允许决赛'
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// Do Stuff
} else {
return super.onKeyDown(keyCode, event);
}
}
Run Code Online (Sandbox Code Playgroud) 我想在溢出下拉菜单中显示菜单项标题以外的图标.
有可能吗?
我已经在Android中为Menus编写了一个代码,但它现在出现在我的活动中,这是我的代码
我这里只显示我的相关代码,
的Manifest.xml
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme" >
Run Code Online (Sandbox Code Playgroud)
MainActivity.Java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up …Run Code Online (Sandbox Code Playgroud)