码迷,mamicode.com
首页 > 移动开发 > 详细

android dialog弹出的情况下监听返回键

时间:2015-11-17 13:02:15      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

view = LayoutInflater.from(getActivity()).inflate(
R.layout.dialog_tips, null);
  title2 = (TextView) view.findViewById(R.id.title2);

 

  dialog = new Dialog(getActivity());
dialog.setOnKeyListener(new OnKeyListener() {

@Override
public boolean onKey(DialogInterface dialog,
int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK
    && event.getRepeatCount() == 0) {
    getActivity().finish();
  }
    return false;
  }
  });
  dialog.getWindow().setBackgroundDrawable(
  new ColorDrawable(
  android.R.color.transparent));
  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.getWindow()
.setLayout(
ScreenUtil
.getScreenWidth(getActivity()) - 50,
DensityUtil.dp2px(400));
dialog.show();

android dialog弹出的情况下监听返回键

标签:

原文地址:http://www.cnblogs.com/zhaoleigege/p/4971045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!