在我下面的片段中
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
root = (ViewGroup) inflater.inflate(R.layout.layout1, null);
setHasOptionsMenu(true);
activity = getActivity();
菜单功能一直有效,直到我添加了一个 onKeyListener。在我添加 onKeyListener 后,菜单不起作用!
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
root = (ViewGroup) inflater.inflate(R.layout.layout1, null);
setHasOptionsMenu(true);
activity = getActivity();
root.setFocusableInTouchMode(true);
root.requestFocus();
root.setOnKeyListener(onKey);
.
.
.
.
OnKeyListener onKey = new OnKeyListener() {
public boolean onKey(View arg0, int keyCode, KeyEvent arg2) {
}
}
在片段中工作的解决方案是什么?