Advertisement
thieumao

Event changed keyboard

Apr 18th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.19 KB | None | 0 0
  1.     private fun listenKeyboardChanged() {
  2.         rootLayoutInFragment.getViewTreeObserver().addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
  3.             override fun onGlobalLayout() {
  4.                 val screenHeight = mBinding!!.rootLayout.rootView.height
  5.                 var rect = Rect()
  6.                 activity.window.decorView.getWindowVisibleDisplayFrame(rect)
  7.                 val keyboardHeight = screenHeight - rect.bottom - getActionBarSize()
  8.                 val defaultLineHeight = CommonUtils.dpToPx(1)
  9.                 if (keyboardHeight > 150) {
  10.                     //updateViewWhenKeyboardChanged(true, keyboardHeight)
  11.                     // show keyboard
  12.                 } else {
  13.                     // hide keyboard
  14.                     //updateViewWhenKeyboardChanged(false, defaultLineHeight)
  15.                 }
  16.             }
  17.         })
  18.     }
  19.  
  20.     private fun getActionBarSize(): Int {
  21.         val styledAttributes = activity.getTheme().obtainStyledAttributes(intArrayOf(android.R.attr.actionBarSize))
  22.         val actionBarSize = styledAttributes.getDimension(0, 0f).toInt()
  23.         styledAttributes.recycle()
  24.         return actionBarSize
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement