監(jiān)聽鍵盤彈起收回

344986770424649240.jpg

評論——回復(fù)評論:走同一個編輯框

recycleAdapter.setOnItemClickListener(new recycleAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
isHuifu = true;
SPUtils.saveBoolean("isHuifu",true);
mHuiFuCid = list.get(position).cid;
showSoftInputFromWindow(activity, editContent);
}
});

點擊彈出指定EditText的 軟鍵盤

public static void showSoftInputFromWindow(Activity activity, EditText editText) {
editText.requestFocus();
InputMethodManager imn = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imn.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
}

由于還要分別是點擊回復(fù)還是直接評論彈出的,而且可能中間用戶收起軟鍵盤,因此要判斷

//獲取屏幕高度
int screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
//閥值設(shè)置為屏幕高度的1/3
final int keyHeight = screenHeight / 3;

    rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) {
                LogUtils.e(TAG, "...監(jiān)聽到軟鍵盤彈起..." + isHuifu);
            } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) {
                boolean isClick = SPUtils.getBoolean("isHuifu",false);
                String strContent = newsDetailWriteComment.getText().toString().trim();
                if (isClick){
                    if (TextUtils.isEmpty(strContent) ) {
                        isHuifu = false;
                        SPUtils.saveBoolean("isHuifu", false);
                        LogUtils.e(TAG, isClick+strContent+"...監(jiān)聽到軟件盤關(guān)閉..." + isHuifu);
                    }
                }
            }
        }
    });
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容