DialogFragment 监听按键事件的方法(onkeydown)


                我们在TV软件开发的时候,会使用DialogFragment,有时候要对它的按键事件进行监听,但是DialogFragment的监听方法和其它的不一样。

 

           方法:

            在onCreateView中加入

this.getDialog().setOnKeyListener(new OnKeyListener()
        {
           public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event){
           if (keyCode == KeyEvent.KEYCODE_SEARCH)
             return true; // pretend we've processed it
           else
             return false; // pass on to be processed as normal
         }
       });

        即可,通过判断各种事件,进行监听处理。希望能够帮到需要的朋友。

         还有 就是  return false和return true是是否允许事件下传,return true是中断事件,那么下面的就接受不到按键信息了,只有在return false的时候 才会事件继续向下传递。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM