How to lowercase the text in the EditText of the searchable item?

android

Solution

I'm surprised there isn't a good answer for this yet. Or maybe it's on another question that I couldn't find.

So here's my solution.

editText.setFilters(new InputFilter[] {
    new InputFilter.AllCaps() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            return String.valueOf(source).toLowerCase();
        }
    }
});

All text in `editText` will be lowercase, no matter what.

You can modify the string however you like. For example: you want all text to be lowercase AND no spaces allowed (let's say it's an email input field)

You can replace that `return ...` like with this:

return String.valueOf(source).toLowerCase().replace(" ", "");

The same way you can allow or reject individual characters. This example replaces all `e` or `E` with `3`.

return String.valueOf(source).replace("e", "3").replace("E", "3");

And so on.

I hope this helps someone.

Problem

I'm using a searchable item with suggestion in my Android project. It is essentially an EditText ``` <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search.hint" android:includeInGlobalSearch="true" android:searchSettingsDescription="@string/search.hint" android:searchSuggestAuthority="com.xxx.android.provider.SearchSuggestionsProvider" android:searchSuggestSelection=" ?" android:inputType="text" android:imeOptions="actionSearch"> </searchable> ``` When I start typing it shows as first letter uppercase. Why? I would like it to start lowercase. Is it possible?

Original source