Jak ukryć miękką klawiaturę po rozpoczęciu aktywności
Mam Edittext z android:windowSoftInputMode="stateVisible"
w manifeście. Teraz Klawiatura zostanie wyświetlona po rozpoczęciu aktywności. Jak to ukryć? Nie mogę użyć android:windowSoftInputMode="stateHidden
, ponieważ gdy klawiatura jest widoczna, zminimalizuj aplikację i wznów ją, klawiatura powinna być widoczna.
Próbowałem z
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
19 answers
Użyj następujących funkcji, aby pokazać / ukryć klawiaturę:
/**
* Hides the soft keyboard
*/
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
/**
* Shows the soft keyboard
*/
public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
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-09-24 09:06:13
W AndroidManifest.xml
:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
Lub spróbuj
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Proszę sprawdzić to również
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-07-31 10:21:14
Wystarczy dodać dwa atrybuty do nadrzędnego widoku editText.
android:focusable="true"
android:focusableInTouchMode="true"
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-04-19 06:48:18
Umieść to w manifeście wewnątrz znacznika aktywności
android:windowSoftInputMode="stateHidden"
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-25 05:31:40
Spróbuj tego:
<activity
...
android:windowSoftInputMode="stateHidden|adjustResize"
...
>
Spójrz na Ten Po Więcej Szczegółów.
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-05-23 12:02:57
Aby ukryć softkeyboard w momencie rozpoczęcia nowej aktywności lub onCreate()
,onStart()
itd. możesz użyć poniższego kodu:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
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
2014-09-11 12:17:50
Dodaj następujący tekst do pliku xml.
<!--Dummy layout that gain focus -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
</LinearLayout>
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
2014-09-22 11:37:18
Mam nadzieję, że to zadziała, próbowałem wielu metod, ale ta zadziałała u mnie w fragments
. wystarczy umieścić tę linię w onCreateview/init.
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
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-04-19 10:07:07
Możesz ustawić config na AndroidManifest.xml
Przykład:
<activity
android:name="Activity"
android:configChanges="orientation|keyboardHidden"
android:theme="@*android:style/Theme.NoTitleBar"
android:launchMode="singleTop"
android:windowSoftInputMode="stateHidden"/>
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-22 05:11:14
Aby ukryć softkeyboard w momencie rozpoczęcia nowej aktywności lub metody onCreate(),onStart() itp. użyj poniższego kodu:
getActivity().getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Aby ukryć softkeyboard w momencie przycisku należy kliknąć w aktywności:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
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-05-17 07:16:07
Umieść ten kod w swoim pliku java i podaj argument dla obiektu na edittext,
private void setHideSoftKeyboard(EditText editText){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
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-01-16 14:09:14
Użyj poniższego kodu, aby ukryć softkeyboard po pierwszym uruchomieniu aktywności
getActivity().getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_HIDDEN);
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-10-28 10:45:14
Oto co zrobiłem:
yourEditText.setCursorVisible(false); //This code is used when you do not want the cursor to be visible at startup
yourEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event); // handle the event first
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0); // hide the soft keyboard
yourEditText.setCursorVisible(true); //This is to display cursor when upon onTouch of Edittext
}
return true;
}
});
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-07-10 03:59:28
Spróbuj tego.
Najpierw w wyszukiwanym xml pola (Nazwa i podpowiedź itp.) umieszczają @string
, a nie literalne ciągi znaków.
Następnie metoda onCreateOptionsMenu
, musi posiadać obiekt ComponentName
z nazwą pakietu i ukończoną nazwą klasy (z nazwą pakietu) - w przypadku aktywności, która ma komponent SearchView
jest taka sama jak w wynikach wyszukiwania Użyj getComponentName()
, Jak mówi programista Google android.
Próbowałem wielu rozwiązań i po wielu, wielu pracach To rozwiązanie działa dla mnie.
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-03-18 03:01:44
Spróbuj również tego
Ed_Cat_Search = (EditText) findViewById(R.id.editText_Searc_Categories);
Ed_Cat_Search.setInputType(InputType.TYPE_NULL);
Ed_Cat_Search.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Ed_Cat_Search.setInputType(InputType.TYPE_CLASS_TEXT);
Ed_Cat_Search.onTouchEvent(event); // call native handler
return true; // consume touch even
}
});
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-01-17 09:07:52
Jeśli Twoja aplikacja jest kierowana na poziom API Androida 21 lub więcej , to jest dostępna domyślna metoda.
editTextObj.setShowSoftInputOnFocus(false);
Upewnij się, że masz ustawiony poniżej kod w znaczniku EditText
XML.
<EditText
....
android:enabled="true"
android:focusable="true" />
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-28 12:45:37
Za Pomocą AndroidManifest.xml
<activity android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden"
/>
Using Java
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Używając powyższej klawiatury rozwiązanie Ukryj, ale edittext nie będzie skupiał się po utworzeniu activiy, ale chwyć go po dotknięciu za pomocą:
Dodaj swój EditText
<EditText
android:focusable="false" />
Dodaj także listener swojego EditText
youredittext.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setFocusable(true);
v.setFocusableInTouchMode(true);
return false;
}});
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-09-27 06:11:22
Ed_Cat_Search = (EditText) findViewById(R.id.editText_Searc_Categories);
Ed_Cat_Search.setInputType(InputType.TYPE_NULL);
Ed_Cat_Search.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Ed_Cat_Search.setInputType(InputType.TYPE_CLASS_TEXT);
Ed_Cat_Search.onTouchEvent(event); // call native handler
return true; // consume touch even
}
});
this one worked for me
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-04-07 15:01:12
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Będzie działać