Android hide soft keyboard IME
<p>Below is a bit of code that I managed to get to work to hide the soft keyboard on android. It works by the user clicking anywhere on the screen (outside of a <code>EditText</code> input/s) to hide the IME soft keyboard. It registers a <code>OnTouchListener</code> to the <code>ScrollView (id="@+id/sv_background)</code> which when the screen is touched it hides the IME soft keyboard via the <code>InputMethodManager</code> code. I have set the scroll view as the parent layout in this case but it also works with any other layout view. </p>

<p>I hope this is useful to someone out there in Android land.</p>

<p>XML</p>

<pre><code>&lt;ScrollView 
android:id="@+id/sv_background" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"&gt;

   &lt;other views and EditTexts/&gt;

&lt;/ScrollView&gt;
</code></pre>

<p>Java</p>

<pre><code>private ScrollView svBackground;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newentry);

    svBackground = (ScrollView)findViewById(R.id.sv_background);
    svBackground.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(svBackground.getWindowToken(), 0);
            return false;
        }
    });
}
</code></pre>
