Android Kotlin适用小函数

  

  都是一些Android适用的Kotlin小函数。

  1.点击空白隐藏键盘

  

 //点击空白隐藏键盘
    override fun onTouchEvent(event: MotionEvent): Boolean {
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if (event.action == MotionEvent.ACTION_DOWN) {
            if (this@LoginMain.currentFocus != null) {
                if (this@LoginMain.currentFocus!!.windowToken != null) {
                    imm.hideSoftInputFromWindow(this@LoginMain.currentFocus!!.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
                }
            }
        }
        return super.onTouchEvent(event)
    }

  

posted @ 2017-10-16 20:53  Jason_Jan  阅读(476)  评论(0编辑  收藏  举报