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

前端 未结 30 1373
情书的邮戳
情书的邮戳 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:40

    If you support apis for AndroidR in your app then you can use the below method.

    In kotlin :
        var imeInsets = view.rootWindowInsets.getInsets(Type.ime()) 
        if (imeInsets.isVisible) { 
            view.translationX = imeInsets.bottom 
        }
    

    Note: This is only available for the AndroidR and below android version needs to follow some of other answer or i will update it for that.

提交回复
热议问题