简体   繁体   中英

How do I turn off Spell checker using code in Android?

I need the Spell Checker to be turned off using Android code. How do I do that? If it cannot be turned off by code, is there a way to display the spell checker options to the user so the user can turn it off manually? thanks

Add this line into your EditText :

android:inputType="textFilter"

And if your EditText accepts multiple lines, then do this:

android:inputType="textFilter|textMultiLine"

Update:

That is not possible to switch it off/on till now via code. But you can do one thing, you can ask user to disable it and if user choose yes then open Language Settings Screen by following code:

Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");
        startActivity(intent);

If this is for an EditText (I think that is what you want) here is a trick:

android:inputType="textVisiblePassword"

You can also OR more types in, incase you wanted like "textCapSentences" as well or "textMultiLine"

eg android:inputType="textVisiblePassword|textMultiLine"

EDIT: You asked for doing this to allow for user to change this. Well add some sort of settings, or a button, that enables / disables auto correct. Then set the flag to true/false based on the flag saved in SharedPreferences. You then retrieve the value any time you are creating the activity that contains the EditText.

ie When user enables auto correct (some button or switch)

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("autoCorrect", true).apply();

When you want to check if the pref is enabled:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean autoCorrectEnabled = prefs.getBoolean("autoCorrect", false);

//change the settings of EditTexts to turn off auto correct / spell checker
if(!autoCorrectEnabled){
    input.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

//enable spell checker 
}else{
    input.setInputType(TYPE_CLASS_TEXT);
}

You basically locally store the user's setting for allowing for auto correct and change the input types of your EditTexts accordingly based on the setting saved. If it is enabled, no user input will cause the keyboard to include auto correct / spell checker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM