Hide Android keyboard [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Stop EditText from gaining focus at Activity startup

    46 answers




I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?










share|improve this question













marked as duplicate by TheWanderer, Community Nov 19 at 18:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • So you have EditTexts in the Activity I'm guessing?
    – TheWanderer
    Nov 15 at 2:13










  • In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
    – Sayok Majumder
    Nov 15 at 9:31

















up vote
0
down vote

favorite













This question already has an answer here:




  • Stop EditText from gaining focus at Activity startup

    46 answers




I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?










share|improve this question













marked as duplicate by TheWanderer, Community Nov 19 at 18:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • So you have EditTexts in the Activity I'm guessing?
    – TheWanderer
    Nov 15 at 2:13










  • In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
    – Sayok Majumder
    Nov 15 at 9:31















up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • Stop EditText from gaining focus at Activity startup

    46 answers




I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?










share|improve this question














This question already has an answer here:




  • Stop EditText from gaining focus at Activity startup

    46 answers




I have been trying to hide the keyboard when user enters an activity,i checked and tried various ways and method but the one I lost see is hide keyboard on button click. I don't want the keyboard to hide on only button, I want it to be hidden when the activity starts. I also tried to put the code in an onCreate method but still the same.another on I saw on Android arsenal was to click on any part of the screen to hide the keyboard was nice but still I still prefer the keyboard hidden when the activity starts, please is there any way hiding the keyboard when the activity starts?





This question already has an answer here:




  • Stop EditText from gaining focus at Activity startup

    46 answers








android android-studio android-layout keyboard






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 at 1:57









Ayodele Kayode

3416




3416




marked as duplicate by TheWanderer, Community Nov 19 at 18:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by TheWanderer, Community Nov 19 at 18:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • So you have EditTexts in the Activity I'm guessing?
    – TheWanderer
    Nov 15 at 2:13










  • In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
    – Sayok Majumder
    Nov 15 at 9:31




















  • So you have EditTexts in the Activity I'm guessing?
    – TheWanderer
    Nov 15 at 2:13










  • In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
    – Sayok Majumder
    Nov 15 at 9:31


















So you have EditTexts in the Activity I'm guessing?
– TheWanderer
Nov 15 at 2:13




So you have EditTexts in the Activity I'm guessing?
– TheWanderer
Nov 15 at 2:13












In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
– Sayok Majumder
Nov 15 at 9:31






In your manifest add ths line inside the <activity> tag add this: android:windowSoftInputMode="stateHidden"
– Sayok Majumder
Nov 15 at 9:31














3 Answers
3






active

oldest

votes

















up vote
0
down vote














Your solution is here




There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.



<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateAlwaysHidden"/>


Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.



Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.






share|improve this answer




























    up vote
    0
    down vote













    Write this line on oncreate method



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






    share|improve this answer




























      up vote
      0
      down vote













      **Use This Method In on create  **   

      public static void hideKeyboard(Activity activity) {
      InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
      //Find the currently focused view, so we can grab the correct window token from it.
      View view = activity.getCurrentFocus();
      //If no view currently has focus, create a new one, just so we can grab a window token from it
      if (view == null) {
      view = new View(activity);
      }
      Objects.requireNonNull(imm).hideSoftInputFromWindow(view.getWindowToken(), 0);
      }





      share|improve this answer






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote














        Your solution is here




        There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.



        <activity
        android:name=".MyActivity"
        android:windowSoftInputMode="stateAlwaysHidden"/>


        Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.



        Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.






        share|improve this answer

























          up vote
          0
          down vote














          Your solution is here




          There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.



          <activity
          android:name=".MyActivity"
          android:windowSoftInputMode="stateAlwaysHidden"/>


          Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.



          Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.






          share|improve this answer























            up vote
            0
            down vote










            up vote
            0
            down vote










            Your solution is here




            There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.



            <activity
            android:name=".MyActivity"
            android:windowSoftInputMode="stateAlwaysHidden"/>


            Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.



            Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.






            share|improve this answer













            Your solution is here




            There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.



            <activity
            android:name=".MyActivity"
            android:windowSoftInputMode="stateAlwaysHidden"/>


            Almost unbelievably, it appears to do nothing to prevent the keyboard from opening when you touch the control (unless focusable="false" and/or focusableInTouchMode="false" are assigned to the control). Apparently, the windowSoftInputMode setting applies only to automatic focus events, not to focus events triggered from touch events.



            Therefore, stateAlwaysHidden is VERY poorly named indeed. It should perhaps be called ignoreInitialFocus instead.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 at 3:06









            user7832102

            379317




            379317
























                up vote
                0
                down vote













                Write this line on oncreate method



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






                share|improve this answer

























                  up vote
                  0
                  down vote













                  Write this line on oncreate method



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






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Write this line on oncreate method



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






                    share|improve this answer












                    Write this line on oncreate method



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







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 15 at 11:08









                    Shiva Kanumala

                    7114




                    7114






















                        up vote
                        0
                        down vote













                        **Use This Method In on create  **   

                        public static void hideKeyboard(Activity activity) {
                        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                        //Find the currently focused view, so we can grab the correct window token from it.
                        View view = activity.getCurrentFocus();
                        //If no view currently has focus, create a new one, just so we can grab a window token from it
                        if (view == null) {
                        view = new View(activity);
                        }
                        Objects.requireNonNull(imm).hideSoftInputFromWindow(view.getWindowToken(), 0);
                        }





                        share|improve this answer



























                          up vote
                          0
                          down vote













                          **Use This Method In on create  **   

                          public static void hideKeyboard(Activity activity) {
                          InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                          //Find the currently focused view, so we can grab the correct window token from it.
                          View view = activity.getCurrentFocus();
                          //If no view currently has focus, create a new one, just so we can grab a window token from it
                          if (view == null) {
                          view = new View(activity);
                          }
                          Objects.requireNonNull(imm).hideSoftInputFromWindow(view.getWindowToken(), 0);
                          }





                          share|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            **Use This Method In on create  **   

                            public static void hideKeyboard(Activity activity) {
                            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                            //Find the currently focused view, so we can grab the correct window token from it.
                            View view = activity.getCurrentFocus();
                            //If no view currently has focus, create a new one, just so we can grab a window token from it
                            if (view == null) {
                            view = new View(activity);
                            }
                            Objects.requireNonNull(imm).hideSoftInputFromWindow(view.getWindowToken(), 0);
                            }





                            share|improve this answer














                            **Use This Method In on create  **   

                            public static void hideKeyboard(Activity activity) {
                            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                            //Find the currently focused view, so we can grab the correct window token from it.
                            View view = activity.getCurrentFocus();
                            //If no view currently has focus, create a new one, just so we can grab a window token from it
                            if (view == null) {
                            view = new View(activity);
                            }
                            Objects.requireNonNull(imm).hideSoftInputFromWindow(view.getWindowToken(), 0);
                            }






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 15 at 11:32

























                            answered Nov 15 at 9:07









                            Masum

                            196




                            196















                                Popular posts from this blog

                                How to change which sound is reproduced for terminal bell?

                                Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?