Auto Collapse ActionBar SearchView on Soft Keyboard close

I’ll expand on @user1258568 ‘s answer for the lazy. This worked for me. Note that it clears your query when focus is lost. final MenuItem searchMenuItem = optionsMenu.findItem(R.id.search); final SearchView searchView = (SearchView) searchMenuItem.getActionView(); searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean queryTextFocused) { if(!queryTextFocused) { searchMenuItem.collapseActionView(); searchView.setQuery(“”, false); } } });

Show soft keyboard for dialog

Awesome question, I was trying to do that too and found a solution. Using the dialog builder class AlertDialog.Builder you will have to invoke the dialog like this: AlertDialog.Builder builder = new AlertDialog.Builder(); AlertDialog dialog; builder.set… dialog = builder.create(); dialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); This worked fine for me. Note: you must import android.view.WindowManager.LayoutParams; for the constant value … Read more

Show entire bottom sheet with EditText above Keyboard

Just reposting @jblejder from this question Keyboard hides BottomSheetDialogFragment since it worked for me, to make it easier for others to find: The most convenient way that I found to change this is by creating style: <style name=”DialogStyle” parent=”Theme.Design.Light.BottomSheetDialog”> <item name=”android:windowIsFloating”>false</item> <item name=”android:statusBarColor”>@android:color/transparent</item> <item name=”android:windowSoftInputMode”>adjustResize</item> </style> And set this in onCreate method of your BottomSheetDialogFragment: … Read more

How to hide the soft keyboard inside a fragment?

As long as your Fragment creates a View, you can use the IBinder (window token) from that view after it has been attached. For example, you can override onActivityCreated in your Fragment: @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); }

Close/hide the Android Soft Keyboard with Kotlin

Use the following utility functions within your Activities, Fragments to hide the soft keyboard. (*)Update for the latest Kotlin version fun Fragment.hideKeyboard() { view?.let { activity?.hideKeyboard(it) } } fun Activity.hideKeyboard() { hideKeyboard(currentFocus ?: View(this)) } fun Context.hideKeyboard(view: View) { val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } This will close the keyboard regardless of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)