Ok, I found a way to do this in a very simple way: XML Layout definition. Since a Layout is a ViewGroup we can implement events on it. Go and define the method to handle a click on the layout (hideSoftKeyboard)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/main_layout"
android:onClick="hideSoftKeyboard" >
And here is how I implemented the method:
public void hideSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}