Android 軟鍵盤的顯示與隱藏監聽

2021-08-21 09:14:20 字數 1395 閱讀 2690

package 

com.util

;import

;import

android.graphics.rect

;import

android.view.view

;import

android.view.viewtreeobserver

;/**

* created by zhaoxin on 2018/7/11.

*/public class

softkeyboardlistener

//根檢視顯示高度沒有變化,可以看作軟鍵盤顯示/隱藏狀態沒有改變

if (

rootviewvisibleheight

== visibleheight)

//根檢視顯示高度變小超過200,可以看作軟鍵盤顯示了

if (

rootviewvisibleheight

- visibleheight >

200)

rootviewvisibleheight

= visibleheight

;return;

}

//根檢視顯示高度變大超過200,可以看作軟鍵盤隱藏了

if (visibleheight -

rootviewvisibleheight

>

200)

rootviewvisibleheight

= visibleheight

;return;

} }

});}

private void

setonsoftkeyboardchangelistener

(onsoftkeyboardchangelistener onsoftkeyboardchangelistener)

public inte***ce

onsoftkeyboardchangelistener

public static void

setlistener

(activity activity

, onsoftkeyboardchangelistener onsoftkeyboardchangelistener)

}

activity 中呼叫

softkeyboardlistener.setlistener(this, new softkeyboardlistener.onsoftkeyboardchangelistener() 

@override

public void

keyboardhide(int height)

});

Android 隱藏 顯示軟鍵盤方法

隱藏軟鍵盤的終極方法 public class softkeyboardutil 隱藏軟鍵盤 可用於activity,fragment public static void hidesoftkeyboard context context,list viewlist 那 softkeyboardut...

Android軟鍵盤的顯示和隱藏

隱藏軟鍵盤 inputmethodmanager imm inputmethodmanager getsystemservice context.input method service imm.togglesoftinput 0 inputmethodmanager.hide not always...

軟鍵盤的顯示與隱藏

如果輸入法在視窗上已經顯示,則隱藏,反之則顯示1 2 inputmethodmanager imm inputmethodmanager getsystemservice context.input method service imm.togglesoftinput 0,inputmethodma...