当前位置: 动力学知识库 > 问答 > 编程问答 >

android - App crashes when clicking hardware-settings-button

问题描述:

I don't have any settings in my app. A friend told me that when pressing the "Settings" button (which I don't see on my emulator btw) the app crashed.

Is there a way to tell Android there are no settings to declare ?

More info : Acer Liquid MT, running Android 2.3.5. See pic (4th button on the right)

网友答案:

I don't have a device with a hardware settings key, so I could not really test it, but I assume should be possible to handle a hardware settings-key click like this in your activity:

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
    if (keycode == KeyEvent.KEYCODE_SETTINGS) { //ignore settings key         
        return true;
    } else {
        return super.onKeyDown(keycode, e);
    }
}

see here the list of Keycode constants here KEYCODE_SETTINGS might be what you are looking for: http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_SETTINGS

网友答案:

Remove this code from your activity. This code is inflating settings menu in your project.

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     // Inflate the menu; this adds items to the action bar if it is present.
     getMenuInflater().inflate(R.menu.main, menu);
     return true;
 }
分享给朋友:
您可能感兴趣的文章:
随机阅读: