英文:
Disable Autocomplete for User Input (within a Java Android App)
问题
我想在我正在开发的一个应用程序中禁用自动更正和自动完成(来自键盘的单词建议)功能,仅限于某个特定应用。这是一个词汇训练应用,所以我希望用户在输入时不使用任何工具。是否有办法用Java实现这一点?以下是一些相关的代码片段:
用户交互部分:
public void onClick(View view) {
TextView textView = (TextView) getView().findViewById(R.id.textview);
final String answer = textView.getText().toString();
passData(answer);
}
XML部分:
<EditText
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#CCCCCC"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
附注:
我是应用开发的新手,所以您可能会在上面的代码中看到一些问题 - 如果是这样,请告诉我!
英文:
I want to disable auto-correction and auto-complete (word suggestions from the keyboard) on my cellphone
within an app I'm working on.
It's a vocabulary trainer, so I want the User to type the input without using any tools.
Is there a way to do this with Java? Some relevant code snippets:
The user-interaction:
public void onClick(View view) {
TextView textView = (TextView) getView().findViewById(R.id.textview);
final String answer = textView.getText().toString();
passData(answer);
}
And the xml:
<EditText
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#CCCCCC"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
P.S.
I'm new to App Development, so you might see some flaws in my code above - in that case, please tell me!
答案1
得分: 1
以下是已翻译的内容:
在您的 EditText
中添加这段代码,看看是否起作用:
android:inputType="text|textNoSuggestions"
而不是:
android:inputType="textPersonName"
这样它会变成这样:
<EditText
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#CCCCCC"
android:ems="10"
android:inputType="text|textNoSuggestions" >
<requestFocus />
</EditText>
英文:
Does it work if you add this to your EditText
:
android:inputType="text|textNoSuggestions"
Instead of:
android:inputType="textPersonName"
So it becomes this:
<EditText
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#CCCCCC"
android:ems="10"
android:inputType="text|textNoSuggestions" >
<requestFocus />
</EditText>
答案2
得分: 1
通过编程
sampleEdt.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
文档
> 可与文本及其变体组合使用,指示输入法不应显示任何基于词典的单词建议。对应于InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS。
英文:
Programatically
sampleEdt.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
Documentation
> Can be combined with text and its variations to indicate that the IME should not show any dictionary-based word suggestions. Corresponds to InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论