I have a situation where I open SearchActivity and I want to have cursor in SearchView (keeping focus) while not showing keyboard at first. When and ONLY when user presses SearchView I want to show keyboard (cursor should be intact)
            Asked
            
        
        
            Active
            
        
            Viewed 1,169 times
        
    3
            
            
         
    
    
        Quick learner
        
- 10,632
- 4
- 45
- 55
 
    
    
        MaaAn13
        
- 264
- 5
- 24
- 54
- 
                    2Possible duplicate of [How to hide Soft Keyboard when activity starts](https://stackoverflow.com/questions/18977187/how-to-hide-soft-keyboard-when-activity-starts) – Santanu Sur Mar 09 '18 at 07:29
- 
                    just hide keyboard when activity starts – Manohar Mar 09 '18 at 07:47
6 Answers
2
            
            
        Add this below line in your activity.xml file's main layout
<LinearLayout
    ...
    android:focusableInTouchMode="true"
    ...
   >
 
    
    
        Chintak Patel
        
- 748
- 6
- 24
0
            
            
        Add this line in Manifest inside SearchActivity
<activity name=".SearchActivity"
android:windowSoftInputMode="stateHidden" />
or In Activity onCreate() add
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
 
    
    
        Rajan Kali
        
- 12,627
- 3
- 25
- 37
0
            
            
        Try this in your SearchActivity in onCreate
 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
 
    
    
        Santanu Sur
        
- 10,997
- 7
- 33
- 52
0
            
            
        add this to your onCreate to hide the kayboard
public void hideSoftKeyboard() {
    if(getCurrentFocus()!=null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}
 
    
    
        diksha
        
- 109
- 8
0
            
            
        you used below code to show key board..
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
and close keyboard used this ...
        imm.hideSoftInputFromWindow(searchView.getWindowToken(),0);
0
            
            
        You gotta hide the softkeyboard after the SearchView gets focus:
search.postDelayed({
        val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.hideSoftInputFromWindow(view?.windowToken, 0)
    }, 100)
 
    
    
        Jose Ricardo Citerio Alcala
        
- 486
- 1
- 7
- 25