我正在尝试控制手机的后退按钮,并在按下后键时设置一个看不见的布局,但没有任何内容出现。我想知道是否有可能这样做。
public boolean onKeyDown(int keyCode, KeyEvent ev) {
switch(keyCode) {
case KeyEvent.KEYCODE_BACK:
if (main_layout.getVisibility() == View.VISIBLE) {
finish();
} else if (sub_layout.getVisibility() == View.VISIBLE){
boutton_radio.setVisibility(View.VISIBLE);
boutton_radio.setEnabled(true);
sub_layout.setEnabled(false);
sub_layout.setVisibility(View.GONE);
main_layout.setVisibility(View.VISIBLE);
main_layout.setEnabled(true);
}
return true;
}
return false;
}
按下后退按钮也会给出相同的结果
@覆盖
public void onBackPressed() {
// TODO Auto-generated method stub
}
答案 0 :(得分:0)
@Override
public void onBackPressed() {
final MediaPlayer areusure = MediaPlayer.create(TalkingWebBrowserActivity.this, R.raw.areusure);
areusure.start();
AlertDialog alertbox = new AlertDialog.Builder(this)
.setMessage("Do you want to exit the Browser?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
}
})
.show();
}
答案 1 :(得分:0)
你走在正确的道路上。 :)
public void onBackPressed() {
if (main_layout.getVisibility() == View.VISIBLE) {
finish();
} else if (sub_layout.getVisibility() == View.VISIBLE){
boutton_radio.setVisibility(View.VISIBLE);
boutton_radio.setEnabled(true);
sub_layout.setEnabled(false);
sub_layout.setVisibility(View.GONE);
main_layout.setVisibility(View.VISIBLE);
main_layout.setEnabled(true);
}
}
答案 2 :(得分:0)
为什么你要检查两个不同的东西。如果你输入你的其他if(main_layout.getVisability而不是sub main。试试看,告诉我这是否解决了