3

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

Hanna F
  • 43
  • 3

2 Answers2

5

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);
Baby Be'el
  • 234
  • 1
  • 4
  • 12
  • No this is not for an edit text, I want this to be system wide, thanks – Hanna F Jan 12 '16 at 19:46
  • @HannaF Updated the answer. The updated answer is the possibility. – Baby Be'el Jan 12 '16 at 20:13
  • this only opens language settings .. not spell checker? you need : com.android.settings.Settings$SpellCheckersSettingsActivity – Mark Jan 12 '16 at 20:23
  • Thank you for your answers Priya and @Mark, they both helped me. I will accept it as the answer. – Hanna F Jan 12 '16 at 20:57
  • No Problem :) Don't forget to upvote the answer. ;) @HannaF – Baby Be'el Jan 12 '16 at 21:04
  • @Priya Dubey .. You are correct, it may not work, but for the sake of 2 minutes writing the code, maybe its worth a go, seeing as this exactly addresses the original question ... – Mark Jan 12 '16 at 22:05
0

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"

e.g. 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.

i.e. 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.

Lucas Crawford
  • 3,078
  • 2
  • 14
  • 25
  • No this is not for an edit text, I want this to be system wide, thanks – Hanna F Jan 12 '16 at 19:45
  • Thanks for your update, though this is only limited to my application, I want the equivalent of the user turning off spell checker on the phone completely. If it can't be done from code, is there a way to display the activity (will have to find out its path) and then the user can manually disable the spell checker – Hanna F Jan 12 '16 at 19:56
  • Oh, I see.. hmm got me on that one. A system preference I'd have to research – Lucas Crawford Jan 12 '16 at 20:07