本文介紹了我們可以在edittext中有不可編輯的文本嗎的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 EditText
.是否可以在同一個 EditText
中讓部分文本不可編輯而其余部分可編輯?
I am using an EditText
. Is it possible to have a part of text uneditable and the rest editable in the same EditText
?
推薦答案
你可以用
editText.setFocusable(false);
或
editText.setEnabled(false);
雖然禁用 EditText
目前不會忽略來自屏幕鍵盤的輸入(我認為這是一個錯誤).
although disabling the EditText
does currently not ignore input from the on-screen keyboard (I think that's a bug).
根據應用程序,最好使用 InputFilter
拒絕所有更改:
Depending on the application it might be better to use an InputFilter
that rejects all changes:
editText.setFilters(new InputFilter[] {
new InputFilter() {
public CharSequence filter(CharSequence src, int start,
int end, Spanned dst, int dstart, int dend) {
return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
}
}
});
另請參閱這個問題.
這篇關于我們可以在edittext中有不可編輯的文本嗎的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!