簡體   English   中英

鍵盤啟動時,Android禁用鍵盤輸入

[英]Android Disable Keyboard Input when Keyboard is Up

Android鍵盤啟動時,我對輸入有疑問。 我正在運行一些驗證(在后端),我需要能夠在按下單個鍵后禁用鍵盤的功能。 我不想卸下鍵盤。 我只想在我驗證然后重新啟用它時將其禁用。 我不知道該怎么做。 謝謝。

您始終可以使用輸入過濾器來解決此問題:

在您的onCreate()中:

editText = (EditText)findViewById(R.id.edittext);
setEditTextMaxLength(1);

if(verifiedAtBackend()) {
    editText.setFilters(new InputFilter[] {});
}

現在創建方法,這會將您的輸入限制為1個字符:

private void setEditTextMaxLength(int length) {
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(length);
    editText.setFilters(FilterArray);
}

private boolean verifiedAtBackend() {
    //call your backend and see if the verification is true. If it is, return true and the filter would get removed.
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM