Jak ukryć miękką klawiaturę Androida w EditText

Mam aktywność z polami EditText i kilkoma przyciskami dla wygody tego, co normalnie byłoby używane do wypełniania tych pól. Jednak gdy użytkownik dotknie jednego z pól EditText Android miękka klawiatura automatycznie pojawia się. Chcę, aby domyślnie pozostało Ukryte, chyba że użytkownik długo naciśnie przycisk menu. Szukałem na to rozwiązania i znalazłem kilka odpowiedzi, ale jak na razie nie mogę ich uruchomić.

Próbowałem "po": {]}

1 - w metodzie onkologicznej,

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

2-również w metodzie onkologicznej,

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);

3 - i fIn plik manifestu,

<activity android:name=".activityName" android:windowSoftInputMode="stateAlwaysHidden"/>
Żadna z tych metod nie działa. Za każdym razem, gdy użytkownik kliknie pole EditText, pojawia się miękka klawiatura. Chcę, aby miękka klawiatura pojawiła się tylko wtedy, gdy użytkownik wyraźnie pokazuje ją przez długie naciśnięcie klawisza menu. Dlaczego to nie działa?
Author: ScubaSteve, 2012-01-25

13 answers

To ci pomoże.]}

editText.setInputType(InputType.TYPE_NULL);

Edytuj:

Aby wyświetlić miękką klawiaturę, musisz wpisać następujący kod w long key press event of menu button

editText.setInputType(InputType.TYPE_CLASS_TEXT);
            editText.requestFocus();
            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
 76
Author: Sandy,
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
2012-01-27 11:30:13

Musisz dodać manifest. Twój plik manifestu wyglądałby następująco:

<activity
...
android:windowSoftInputMode="stateHidden|adjustResize"
...
>
 27
Author: Emran Hamza,
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-08-21 13:26:21

Czasami używam trochę sztuczki, aby to zrobić. Umieściłem niewidzialny uchwyt ostrości gdzieś na górze układu. Byłoby to np. tak

 <EditText android:id="@id/editInvisibleFocusHolder"
          style="@style/InvisibleFocusHolder"/>

W tym stylu

<style name="InvisibleFocusHolder">
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">0dp</item>
    <item name="android:focusable">true</item>
    <item name="android:focusableInTouchMode">true</item>
    <item name="android:inputType">none</item>
</style>

I wtedy w onResume zadzwoniłbym

    editInvisibleFocusHolder.setInputType(InputType.TYPE_NULL);
    editInvisibleFocusHolder.requestFocus();
To działa mi ładnie od 1.6 do 4.x
 8
Author: Manfred Moser,
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
2012-01-25 04:20:59

Po długim czasie przeglądania klasy TextView znalazłem sposób, aby zapobiec pojawianiu się klawiatury. Sztuczka polega na ukryciu go zaraz po pojawieniu się, więc przeszukałem metodę, która jest wywoływana po pojawieniu się klawiatury i ukryciu jej.

Zaimplementowana Klasa EditText

public class NoImeEditText extends EditText {

    public NoImeEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * This method is called before keyboard appears when text is selected.
     * So just hide the keyboard
     * @return
     */
    @Override
    public boolean onCheckIsTextEditor() {
        hideKeyboard();

        return super.onCheckIsTextEditor();
    }

    /**
     * This methdod is called when text selection is changed, so hide keyboard to prevent it to appear
     * @param selStart
     * @param selEnd
     */
    @Override
    protected void onSelectionChanged(int selStart, int selEnd) {
        super.onSelectionChanged(selStart, selEnd);

        hideKeyboard();
    }

    private void hideKeyboard(){
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getWindowToken(), 0);
    }
}

I styl

<com.my.app.CustomViews.NoImeEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:editable="false"
    android:background="@null"
    android:textSize="@dimen/cell_text" />
 7
Author: cristianomad,
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-05-07 14:51:00

Miękka klawiatura wciąż podnosiła się, mimo że ustawiłem EditorInfo.TYPE_NULL do widoku. Żadna z odpowiedzi nie zadziałała na mnie, poza pomysłem, który zaczerpnąłem z odpowiedzi nik431:

editText.setCursorVisible(false);
editText.setFocusableInTouchMode(false);
editText.setFocusable(false);
 5
Author: Alex Burdusel,
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-10-20 08:00:06

Poniższy wiersz jest dokładnie tym, czego szukamy. Metoda ta została dołączona do API 21, dlatego działa dla API 21 i wyżej.

edittext.setShowSoftInputOnFocus(false);
 2
Author: Shnkc,
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-05-04 12:31:09

Wydaje się, że istnieje wiele sposobów zapobiegania pojawianiu się klawiatury systemowej, zarówno programowo, jak i w xml. Jednak w ten sposób działa dla mnie obsługa urządzeń pre API 11.

// prevent system keyboard from appearing
if (android.os.Build.VERSION.SDK_INT >= 11) {
    editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
    editText.setTextIsSelectable(true);
} else {
    editText.setRawInputType(InputType.TYPE_NULL);
    editText.setFocusable(true);
}
 2
Author: Suragch,
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-11-26 12:55:21

Spróbujmy ustawić poniższe właściwości w Twoim xml dla EditText

android:focusableInTouchMode="true" android:cursorVisible="false".

Jeśli chcesz ukryć softkeypad podczas uruchamiania aktywności, przejdź przez ten link

 1
Author: nik431,
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-11-30 11:09:59
weekText = (EditText) layout.findViewById(R.id.weekEditText);
weekText.setInputType(InputType.TYPE_NULL);
 0
Author: TOLIN THOMAS,
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-02 11:10:49

Trzy sposoby oparte na tej samej prostej instrukcji:

A). Wyniki tak proste jak locate (1):

android:focusableInTouchMode="true"

Wśród konfiguracji dowolnego elementu precedensowego w układzie, przykład:

Jeśli cały układ składa się z:

<ImageView>

<EditTextView>

<EditTextView>

<EditTextView>

Następnie możesz wpisać (1) wśród parametrów ImageView, a to przyciągnie uwagę Androida do ImageView zamiast EditText.

B). Jeśli masz inny element precedensowy niż ImageView, może być konieczne dodanie (2) do (1) as:

android:focusable="true"

C). możesz również po prostu utworzyć pusty element u góry elementów widoku:

<LinearLayout
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:layout_width="0px"
  android:layout_height="0px" />

Ta alternatywa do tego punktu skutkuje jako najprostsza ze wszystkich, jakie widziałem. Mam nadzieję, że to pomoże...

 0
Author: Andrew,
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-03-13 09:04:37

Ukryj klawiaturę

editText.setInputType(InputType.TYPE_NULL);

Pokaż Klawiaturę

etData.setInputType(InputType.TYPE_CLASS_TEXT);
etData.setFocusableInTouchMode(true);

W układzie nadrzędnym

android:focusable="false"
 0
Author: Woz,
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-03-19 23:10:44

Mój wynik testu:

With: editText.setInputType (InputType.TYPE_NULL);

Softkeyboard zniknie, ale kursor również zniknie.

With: editText.setShowSoftInputOnFocus (false)

Działa zgodnie z oczekiwaniami.

 0
Author: David Guo,
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-06 02:06:13

Po Prostu Użyj EditText.setFocusable(false); w aktywności

Lub użyj w xml

android:focusable="false"
 0
Author: Nur Gazi,
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-11 17:32:13