如何实时关闭活动,显示对话?

时间:2016-01-15 09:57:02

标签: android android-dialog

如何完成激活对话的活动?

添加了对话框

AddSyncContactDialog dialog = new AddSyncContactDialog();
    Bundle d = new Bundle();
    d.putString("number", nums.get(nums.size() - 1));
    dialog.setArguments(d);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.addToBackStack(null);
    dialog.show(ft, nums.get(nums.size() - 1));

在活动onBackPressed

  @Override public void onBackPressed() {
    finish();
  }

但它仍然关闭对话,但不关闭活动

1 个答案:

答案 0 :(得分:0)

使用像

这样的对话框的keylistener
dialog.setOnKeyListener(new OnKeyListener() {           
    @Override
    public boolean onKey(DialogInterface dialog1, int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub              
        if(keyCode == KeyEvent.KEYCODE_BACK){                       
            finish();
        }
        return true;
    }
});

并设置dialog.setCancelable(true);