たくさんの自由帳

Androidアプリ側でキーボードの学習機能を無効にしたい

投稿日 : | 0 日前

文字数(だいたい) : 2061

どうもこんばんわ。
これは D.C.4 の 白河ひより ちゃん ↘

Imgur

本題

アプリ側でIMEの学習機能をOFFに出来ます。
ChromeとかFirefoxのプライベートモードでやましい事を検索しようとする際に有効になったりする。

全てのキーボードアプリが対応してるかは分からん...

作り方

EditTextandroid:imeOptions="flagNoPersonalizedLearning"を指定するだけです、はい

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/edit_text_disable_leaning"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="IMEの学習機能がOFFです"
        android:imeOptions="flagNoPersonalizedLearning"
        android:minHeight="48dp"
        android:text=""
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="IMEの学習機能がONです"
        android:minHeight="48dp"
        android:text=""
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edit_text_disable_leaning" />

</androidx.constraintlayout.widget.ConstraintLayout>

これで実行すると、EditTextが2つ出てると思います。
上のEditTextでは何回同じキーワードを入れても学習しない(入力候補に出るが優先順位が変わらない)が、下のEditTextでは特に指定していないため、
2回目以降は入力候補に優先的に表示されていると思います。

Imgur 若干キーボードのUIが変わる。

Imgur

以上です。

おわりに

最近ねむい