【发布时间】:2018-04-12 12:16:56
【问题描述】:
我已经为此苦苦思索了几个晚上。我似乎无法让 EditText(设置为 AlertDialog 的视图)在输入文本时自动进行拼写检查,即使我知道拼写检查已启用,因为它在其他地方工作:
错误显示拼写检查不起作用
我看过几篇开发人员希望禁用拼写检查的帖子,但没有任何帖子无法解决。这是因为我正在使用 AlertDialog(EditTexts 其他地方正在工作)而被禁用,如果是这样,除了 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();
更新:
我刚刚尝试扩充以下布局文件:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtJournalSummaryLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Please summarize your experience studying:"
android:textAlignment="center"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/txtJournalNewSummary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="6"
android:minLines="3"
android:singleLine="false"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtJournalSummaryLabel" />
</android.support.constraint.ConstraintLayout>
到警报对话框:
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 仍然没有显示拼写错误。这是因为视图未附加到父 Activity/Fragment 吗?任何帮助将不胜感激。
【问题讨论】:
-
感谢@Navneet 编辑图片。我自己距离能够做到这一点还有2分。 :)
标签: java android android-edittext spell-checking