When you create a search apps, you usually use EditText for the search box. It’s a little bit annoying when the application started and it get EditText focused and show soft keyboard automatically. To make Edittext not focus and not showing soft keyboard when your application started, then you can follow this step:
1. We create Layout that will be used as first focus when application started.
xml :
1 2 3 4 5 | <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px" /> |
So, when your application started, this Layout will set as default focus and remember it have zero width and heigth which mean user doesn’t see this.
2. Trigger soft-keyboard programmatically when user focused on search box.
Activity :
1 2 3 4 5 6 7 8 9 10 11 | final EditText search = (EditText) this.findViewById(R.id.searchbox); search.setFocusable(true); // Show soft keyboard when user focusd on this search box search.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { InputMethodManager inputStatus = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputStatus.showSoftInput(search, InputMethodManager.SHOW_IMPLICIT); } }); |
When your application started, it doesnt focused on EditText automatically and not showing soft-keyboard which it will provide more clean UI for user.