我想要做的是拦截来自外部类的后退按钮按下,如下所示:
public class AnswerView extends RelativeLayout {
public AnswerView(Context context) {
super(context);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
Log.i("AlleAntwoorden", "Back button pressed!");
return true;
}
return super.onKeyDown(keyCode, event);
}
}
我正在从我的主要活动中添加它:
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
mainLayout.addView(new AnswerView(this));