How do I detect if software keyboard is visible on Android Device or not?

前端 未结 30 1852
情书的邮戳
情书的邮戳 2020-11-22 10:59

Is there a way in Android to detect if the software (a.k.a. \"soft\") keyboard is visible on screen?

30条回答
  •  遥遥无期
    2020-11-22 11:34

    There's finally a direct way starting from Android R based on Kotlin now.

     val imeInsets = view.rootWindowInsets.getInsets(Type.ime()) 
        if (imeInsets.isVisible) { 
         //Ime is visible
         //Lets move our view by the height of the IME
         view.translationX = imeInsets.bottom }
    

提交回复
热议问题