Disable the search button in Android

前端 未结 4 399
眼角桃花
眼角桃花 2021-01-14 05:45

I have a dialog in an Android app that I don\'t want the user to be able to cancel. Using .setCancelable(false) disables the back button, but pressing the sear

4条回答
  •  既然无缘
    2021-01-14 06:14

    @Benh You need this code to set for your Key Listener for Dialog

       builder.setOnKeyListener(keylistener);
    

    Add Below code in your Activity Class

      OnKeyListener keylistener=new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true; //we stop begin cancel of dialog or Progressbar
            }
            return false; 
        }
    }; 
    

    try this above thing in your dialog hope that will work for you.

提交回复
热议问题