簡體   English   中英

如何以編程方式禁用預測文本(沒有EditText)

[英]How to programmatically disable predictive text (with no EditText)

有一個Android應用程序包含自制的輸入字段(沒有TextViewEditText元素),所以我必須顯示/隱藏鍵盤,處理用戶輸入並顯示我自己輸入的符號。

我需要禁用標准視圖的預測文本模式。 不幸的是,Android View類(android.view.View)沒有函數setInputType

有一個可能的解決方案。 獲取給定視圖的InputConnection並更改其屬性。 但我找不到如何獲取和設置當前InputConnection實例,遺憾的是,函數onCreateInputConnection也未被調用。

是否有任何方法可以禁用標准視圖的預測文本模式?

我用過的東西是下面 - 特別是標簽“textNoSuggestions”我認為對你有用!

<EditText android:layout_marginLeft="10px" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginRight="10px"
android:id="@+id/setupactivity_ftpsite" 
android:inputType="textNoSuggestions|textUri">

對不起,這里是一個更簡潔的答案!

與此類似的東西:

1)顯示鍵盤:

InputMethodManager imm =  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(myCustomView, InputMethodManager.SHOW_IMPLICIT);

2)在myCustomView(擴展視圖)中,添加:

 InputConnection onCreateInputConnection (EditorInfo outAttrs) {
     InputConnection ic = new EditableInputConnection(this);
     outAttrs.inputType = TYPE_TEXT_FLAG_NO_SUGGESTIONS;
     outAttrs.initialCapsMode = ic.getCursorCapsMode(outAttrs.inputType); //guess on this
     return ic;
}

這是應該做的總體要點。 你可能想要OR outAttrs.inputType而不是設置相等,所以它保留默認狀態,或者首先調用父onCreateInputConnection,然后只設置你的outAttrs.inputType(不確定這是否有效)。 這應該可以讓您非常接近您的解決方案。

暫無
暫無

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

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