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); }

How to change background color of key for android soft keyboard?

Add this line of code to your input.xml android:keyBackground=”@drawable/samplekeybackground” So your input.xml should end up looking similar to this. <com.example.keyboard.LatinKeyboardView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/keyboard” android:layout_alignParentBottom=”true” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:keyPreviewLayout=”@layout/input_key_preview” android:keyBackground=”@drawable/samplekeybackground” /> If you already have a drawable to use great otherwise here is a sample key background drawable that will produce results like your example image. <?xml version=”1.0″ … Read more

How to include suggestions in Android Keyboard

You can use the static method UserDictionary.Words.addWord(….): Link if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // On JellyBean & above, you can provide a shortcut and an explicit Locale UserDictionary.Words.addWord(this, “MadeUpWord”, 10, “Mad”, Locale.getDefault()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) { UserDictionary.Words.addWord(this, “MadeUpWord”, 10, UserDictionary.Words.LOCALE_TYPE_CURRENT); } You will need to add this permission to your manifest: <uses-permission … Read more

Android Hide Soft Keyboard from EditText while not losing cursor

This worked for me: // Update the EditText so it won’t popup Android’s own keyboard, since I have my own. EditText editText = (EditText)findViewById(R.id.edit_mine); editText.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.onTouchEvent(event); InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } return true; } });

Keyboard hides BottomSheetDialogFragment

I found the solution for 27 api. So the reason why keyboard hides view even with SOFT_INPUT_ADJUST_RESIZE is that the windowIsFloating is set for Dialogs. 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 … Read more

AlertDialog with EditText, open soft keyboard automatically with focus on EditText doesn’t work

Ok I managed to get it working: Builder builder = new Builder(this); final EditText input = new EditText(this); builder .setTitle(R.string.dialog_title_addsubject) .setMessage(R.string.dialog_addsubject) .setView(input) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String value = input.getText().toString(); if (input.getText().toString().trim().length() == 0) { Toast.makeText(Main.this, R.string.input_empty, Toast.LENGTH_SHORT).show(); } else { db.insertSubject(value); getData(); } InputMethodManager imm = (InputMethodManager) … Read more

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