Pierwsza litera Wielka dla EditText

Pracuję nad małą osobistą listą zadań i do tej pory wszystko działało całkiem dobrze. Jest jeden mały dziwak, który chciałbym rozgryźć. Za każdym razem, gdy idę dodać nowy element, Mam okno dialogowe z widokiem EditText wyświetlane wewnątrz. Kiedy zaznaczę Widok EditText, pojawi się klawiatura, aby wprowadzić tekst, tak jak powinien. W większości aplikacji domyślnym wydaje się, że klawisz shift jest trzymany dla pierwszej litery... chociaż to nie robi tego dla mojej opinii. Musi być prosty sposób na naprawić, ale przeszukałem referencję wielokrotnie i nie mogę go znaleźć. Myślę, że musi być atrybut xml dla odniesienia ładowanego przez Adapter, ale nie mogę dowiedzieć się, co to jest.

Author: MiguelHincapieC, 2011-01-26

11 answers

Statycznie (np. w pliku XML układu): Ustaw {[1] } na swoim EditText.

Programowo: musisz dołączyć InputType.TYPE_CLASS_TEXT do InputType z EditText, np.

EditText editor = new EditText(this); 
editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

Może być łączony z tekstem i jego odmianami, aby zażądać wielkiej litery pierwszego znaku każdego zdania.

- Google Docs

 727
Author: McStretch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-16 06:40:33

Po prostu użyj android:inputType="textCapWords" w elemencie EditText.

Na przykład:

<EditText
    android:id="@+id/txtName"
    android:layout_width="0dp"
    android:layout_height="40dp"
    android:layout_weight="0.7"
    android:inputType="textCapWords"
    android:textColorHint="#aaa"
    android:hint="Name Surname"
    android:textSize="12sp" />

Zobacz poniższy link w celach informacyjnych: http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType

 62
Author: Mangi Morobe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-03 04:33:51
testEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);   

Lub android:inputType="textCapSentences" będzie działać tylko wtedy, gdy włączone jest ustawienie automatycznej kapitalizacji klawiatury urządzenia.

 25
Author: Lakshmanan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-16 18:13:20

Zastosuj następujący wiersz w edytorze w XML.

android:inputType="textCapSentences|textMultiLine"

Pozwoli również na obsługę wielu linii.

 19
Author: Shivang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-05 15:57:44

Natknąłem się na ten sam problem, dzieląc się tym, co odkryłem. Może pomóc Tobie i innym...

Spróbuj tego na swoim układzie.dodaj poniższy wiersz w swoim EditText.

android:inputType="textCapWords|textCapSentences"
Na mnie działa.. mam nadzieję, że działa również na Ciebie...
 14
Author: user4144348,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-29 12:16:35

Ustaw typ wejścia w formacie XML jak i w pliku JAVA tak,

W XML,

Android: inputType= "textMultiLine|textCapSentences"

Pozwoli również multiline i w pliku JAVA,

edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

Upewnij się, że ustawienie Automatyczna kapitalizacja jest włączone .

 1
Author: Siddharth Sheth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-15 11:21:45

Zapewniam cię, że zarówno pierwsza litera będzie wielka, jak i nie będzie edytowana pojedynczą linijką.

Jeśli chcesz to zrobić w XMl poniżej znajduje się kod

android:inputType="textCapWords|textCapSentences"

Jeśli chcesz to zrobić w activity / fragment etc poniżej znajduje się kod

momentTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_TEXT_FLAG_MULTI_LINE)

PS: Jeśli posiadasz inną właściwość, możesz ją łatwo dodać za pomocą symbolu"|", po prostu upewnij się, że nie ma miejsca w XML między właściwościami atrybutu

 1
Author: Tushar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-20 17:03:40

W pliku XML układu: Ustaw android: inputType="textCapSentences" na Twoim EditText, aby mieć pierwszy alfabet pierwszego słowa każdego zdania jako Duże Lub android: inputType="textCapWords" na Twoim EditText, aby mieć pierwszy alfabet każdego słowa jako Duże

 1
Author: Himmat Gill,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-20 18:48:41

Wypróbuj ten kod, będzie on pisany wielką literą pierwszego znaku wszystkich słów.

- Ustaw addTextChangedListener dla widoku EditText

Edt_text.addTextChangedListener (watcher);

- Dodaj Texttwatcher

TextWatcher watcher = new TextWatcher() {
    int mStart = 0;

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        mStart = start + count;
    }

    @Override
    public void afterTextChanged(Editable s) {
        String input = s.toString();
        String capitalizedText;
        if (input.length() < 1)
            capitalizedText = input;
        else if (input.length() > 1 && input.contains(" ")) {
            String fstr = input.substring(0, input.lastIndexOf(" ") + 1);
            if (fstr.length() == input.length()) {
                capitalizedText = fstr;
            } else {
                String sstr = input.substring(input.lastIndexOf(" ") + 1);
                sstr = sstr.substring(0, 1).toUpperCase() + sstr.substring(1);
                capitalizedText = fstr + sstr;
            }
        } else
            capitalizedText = input.substring(0, 1).toUpperCase() + input.substring(1);

        if (!capitalizedText.equals(edt_text.getText().toString())) {
            edt_text.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    edt_text.setSelection(mStart);
                    edt_text.removeTextChangedListener(this);
                }
            });
            edt_text.setText(capitalizedText);
        }
    }
};
 0
Author: Dharmesh Patel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-29 12:33:10

Wcześniej był android:capitalize="words", który jest obecnie przestarzały. Zalecaną alternatywą jest użycie android:inputType="textCapWords"

Zwróć uwagę, że będzie to działać tylko wtedy, gdy włączone jest ustawienie automatycznej kapitalizacji klawiatury urządzenia.

Aby zrobić to programowo, użyj następującej metody:

setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);

 0
Author: Mahendra Liya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-27 06:14:41

Użyj tego kodu tylko do pierwszej litery z wielką literą dla EditText

Główna aktywność.xml

<RelativeLayout 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">

    <EditText
        android:id="@+id/et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:tag="true">
    </EditText>

</RelativeLayout>

Główna aktywność.java

EditText et = findViewById(R.id.et);
        et.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {
                if (et.getText().toString().length() == 1 && et.getTag().toString().equals("true"))
                {
                    et.setTag("false");
                    et.setText(et.getText().toString().toUpperCase());
                    et.setSelection(et.getText().toString().length());
                }
                if(et.getText().toString().length() == 0)
                {
                    et.setTag("true");
                }
            }

            public void afterTextChanged(Editable editable) {

            }
        });
 0
Author: milan pithadia,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-16 08:46:27