Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Soft Input in OnCreate

I have a TableLayout that I am dynamically adding content to in code in OnCreate. Once the Activity creates, it is focusing on one of my dynamically created EditTexts and displaying the keyboard. I don't want the keyboard to display until the user specifically presses one of the EditTexts. I've tried:

InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);

But the keyboard still displays and CurrentFocus returns null. So when I attempt to specifically point the focus to another view and then perform the above like:

InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
title.FindFocus();
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);

CurrentFocus is still null and the keyboard still displays. title is a TextView that I already have an instance of in code. Can I just not give focus to a TextView or is there something else I'm missing?

like image 435
jmease Avatar asked Apr 20 '12 13:04

jmease


People also ask

How do I hide my soft keyboard?

Hiding the Soft Keyboard Programmatically You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.

How do I hide soft keyboard when EditText is focused?

setShowSoftInputOnFocus(false); to disable the software keyboard showing when the EditText is touched. the hideKeyboard(this); call in OnCreate to forcible hide the software keyboard.

How do I hide the activity on my keyboard?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.


2 Answers

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
like image 50
Buda Gavril Avatar answered Oct 20 '22 09:10

Buda Gavril


Very Easy

  1. Go to your AndroidManifest.xml file
  2. In your activity add: android:windowSoftInputMode="stateHidden"

For example:

<activity
         android:name=".package.example.MyActivity"
            android:windowSoftInputMode="stateHidden"/>
like image 10
CommonSenseCode Avatar answered Oct 20 '22 10:10

CommonSenseCode