프로그래밍/android

[android] DialogFragment keyEvent (키 이벤트 수신)

-샤리- 2021. 6. 4. 15:07

▣ 키 이벤트 수신 선언

private val keyEventListener = DialogInterface.OnKeyListener {_, keyCode, event ->
        if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN){
            
        }
        true
    }

 

▣ 적용

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        dialog.setOnKeyListener(keyEventListener)
        return inflater.inflate(R.layout.yours, container, false)
    }