コンテンツ
非表示
ソフトウェアキーボードの表示を判定する
こちらを参考にさせて頂きました。
実現したいこと
例えば左図の様なWebView + FBAアイコンの画面があった場合、入力欄をタップすると、右図の様に FABアイコンがせりあがってしまうため、非表示にしたい。


対応方法
LinearLayoutを拡張したクラスのonMeasure()内で判定条件を作成する
1 2 3 4 5 6 7 |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int viewHeight = View.MeasureSpec.getSize(heightMeasureSpec); Activity activity = (Activity) getContext(); Rect rect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight(); |
14 |
onMeasure()内で判定した結果を渡すインタフェース
1 2 3 |
public interface OnSoftKeyShownListener { public void onSoftKeyShown(boolean isShown); } |
Activityなど判定情報が欲しいところから参照する
1 2 3 4 5 6 |
DetectableSoftKeyLayout.OnSoftKeyShownListener listner = new DetectableSoftKeyLayout.OnSoftKeyShownListener() { @Override public void onSoftKeyShown(boolean isShown) { /* true is keyboard is show */ } }; |
結果
無事、キーボード表示時にFBAアイコンを非表示にすることが出来ました。
