daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun ViewGroup.onKeyboardStateChanged(activity: Activity, listener: (Boolean) -> Unit) {
  2.  
  3.     viewTreeObserver.addOnGlobalLayoutListener {
  4.        
  5.         //Размер экрана
  6.         val screenSize = Point()
  7.         activity.windowManager.defaultDisplay.getSize(screenSize)
  8.  
  9.         //Размер фрейма, который видит пользователь
  10.         val rect = Rect()
  11.         getWindowVisibleDisplayFrame(rect)
  12.  
  13.         //Если есть разница -- значит что-то произошло. Вероятно, показалась клавиатура
  14.         val diff = screenSize.y - rect.bottom
  15.         listener.invoke(diff != 0)
  16.     }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top