结束();按下后退按钮一秒钟时不起作用,只有当前按下按钮的可见和不可见功能
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
final ImageView im = (ImageView)findViewById(R.id.imageView);
final ScrollView scrol = (ScrollView)findViewById(R.id.scrollView);
final LinearLayout layOut = (LinearLayout)findViewById(R.id.layout);
final TextView text = (TextView)findViewById(R.id.textView);
final VideoView videoview = (VideoView) findViewById(R.id.video_View);
videoview.setVisibility(View.INVISIBLE);
im.setVisibility(View.VISIBLE);
scrol.setVisibility(View.VISIBLE);
layOut.setVisibility(View.VISIBLE);
text.setVisibility(View.VISIBLE);
return false;
} else {
finish();
}
return super.onKeyDown(keyCode,event);
}
答案 0 :(得分:0)
无法构建apk
@Override
public void onBackPressed(){
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == android.view.KeyEvent.KEYCODE_BACK){
final ImageView im = (ImageView)findViewById(R.id.imageView);
final ScrollView scrol = (ScrollView)findViewById(R.id.scrollView);
final LinearLayout layOut = (LinearLayout)findViewById(R.id.layout);
final TextView text = (TextView)findViewById(R.id.textView);
final VideoView videoview = (VideoView) findViewById(R.id.video_View);
videoview.setVisibility(View.INVISIBLE);
im.setVisibility(View.VISIBLE);
scrol.setVisibility(View.VISIBLE);
layOut.setVisibility(View.VISIBLE);
text.setVisibility(View.VISIBLE);
return false;
} else {
finish();
}
return super.onKeyDown(keyCode, event);
}
}