EditText AlertDialog中的java拼写检查不工作
我已经为这件事抓狂了好几个晚上了。我似乎无法获得EditText(设置为AlertDialog的视图)在输入文本时自动进行拼写检查,即使我知道拼写检查已启用,因为它在其他地方工作:
显示拼写检查无效时出错
我看过几篇文章,开发人员希望禁用拼写检查,但没有一篇文章没有任何解决方案。这是因为我正在使用AlertDialog(其他地方的EditText正在工作)而禁用的吗?如果是,除了AlertDialog之外,还有什么解决方法或其他解决方案可以尝试吗
这是我的密码:
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final EditText input = new EditText(getActivity());
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES|InputType.TYPE_TEXT_FLAG_AUTO_CORRECT|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); //I have tried all combinations of InputType options, including no options.
input.setSingleLine(false);
input.setMaxLines(6);
input.setText("Some Default Text");
input.setSelectAllOnFocus(true);
input.requestFocus();
builder.setView(input);
builder.show();
更新:
我刚刚尝试膨胀以下布局文件:
<安卓.support.constraint.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
<TextView
安卓:id="@+id/txtJournalSummaryLabel"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="8dp"
安卓:layout_marginStart="8dp"
安卓:layout_marginTop="8dp"
安卓:text="Please summarize your experience studying:"
安卓:textAlignment="center"
安卓:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
安卓:id="@+id/txtJournalNewSummary"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_marginBottom="8dp"
安卓:layout_marginEnd="8dp"
安卓:layout_marginStart="8dp"
安卓:layout_marginTop="8dp"
安卓:ems="10"
安卓:inputType="textCapSentences|textMultiLine"
安卓:maxLines="6"
安卓:minLines="3"
安卓:singleLine="false"
安卓:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtJournalSummaryLabel" />
</安卓.support.constraint.ConstraintLayout>
到AlertDialog:
View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_journal_summary_prompt, null);
final EditText txtInput = view.findViewById("Some Default Text");
txtInput.setText(this.journalTitles.get(0));
builder.setView(view);
但是AlertDialog仍然没有显示拼写错误。这是因为视图未附加到父活动/片段吗?任何帮助都将不胜感激
# 1 楼答案
想出了一个解决办法。由于某些原因,当直接将EditText插入生成器,然后为inputType应用textAutoCorrect标志时,拼写检查将不起作用
image showing autocorrect working
解决方案是使用EditText创建布局文件(请参见上面修改的问题),,但请确保在xml资源文件中启用textAutoCorrect标志,将膨胀视图应用于AlertDialog builder,然后观察其工作情况
我希望它能自动更正手动放置在它们(以前的值)中的内容,但这对我来说已经足够好了。把我的解决方案留给后代