はじめに
今回記事にするのは、EditTextの機能内についた IMEというものの学習機能をオフにするやり方です。
IMEについてはGoogleで調べた内容を引用しておきます。
「IME(アイ・エム・イー)」は“Input Method Editor”の略で、直訳すると“入力方法編集プログラム”です。 パソコンに日本語を入力するときは、キーボードから「かな入力」か「ローマ字入力」でひらがなを入力し、それを漢字やカタカナなどを含む文章に変換します。
実践
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/edit_text_disable_leaning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoPersonalizedLearning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
xmlのEditText内で
android:imeOptions=""
というキーボードのEnterキーを矢印やチェックマークに変更したりするときに用いるものを利用し、flagNoPersonalizedLearningを指定するだけです。
これで、キーボードに一度入力された内容が予測変換に出てこなくなります。
また、このEditText内で使用した単語も、通常のキーボードで使用する際の予測変換へは影響が出ないものになっています。
参考