无论焦点如何调用onKeyDown?

时间:2016-09-19 15:54:42

标签: android focus android-studio-2.1

我发现onKeyDown()调用当前选中的视图。有没有办法让我的活动无论关注焦点都能抓住事件?

我的课程如果有兴趣:

MaterialFilePicker filePicker;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Start File Picker
    filePicker = new MaterialFilePicker();
    filePicker.withActivity(this)
            .withRequestCode(1)
            .withHiddenFiles(true) // Show hidden files and folder
            .start();

    //Let DataManager prepare the application
    DataManager.StartUp(this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1 && resultCode == RESULT_OK) {
        DataManager.File = new File(data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH));
        startActivity(new Intent(this, SectionChooserActivity.class));
    }
}

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
    //This method will never get called :/
    switch (keycode) {
        case KeyEvent.KEYCODE_MENU:
            Stuff();
            return true;
    }
    return super.onKeyDown(keycode, e);
}

1 个答案:

答案 0 :(得分:0)

我认为您可以实施onKeyDown之前调用的dispatchKeyEvent

从这里得到它:https://stackoverflow.com/a/6093631/1028256