android-softkeyboard

Close/hide the Android Soft Keyboard with Kotlin

吃可爱长大的小学妹 提交于 2019-12-02 17:29:25
I'm trying to write a simple Android app in Kotlin. I have an EditText and a Button in my layout. After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard. There is a popular question Close/hide the Android Soft Keyboard about doing it in Java, but as far as I understand, there should be an alternative version for Kotlin. How should I do it? I think we can improve Viktor's answer a little. Based on it's always attached to a view, there will be context, if there is context then there is InputMethodManager fun View.hideKeyboard() { val imm = context

Hide keyboard when navigating from a fragment to another

半城伤御伤魂 提交于 2019-12-02 17:06:39
I have a Fragment that contains an Edit Text. When the Edit Text is pressed, the keyboard is being shown. When pressed the Save button in the upper corner, the application returns to the previous fragment, but the keyboard persists. I would like the keyboard to be hidden when navigating to the previous fragment. Please, note that I tried this solution: Close/hide the Android Soft Keyboard . InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myView.getWindowToken(), 0); I tried to use this in both fragments, in

android set hidden the keyboard on press enter (in a EditText)

核能气质少年 提交于 2019-12-02 16:39:36
When my user press Enter on the virtual android "user validate entry!" keyboard my keyboard stay visible! (Why?) Here my Java code... private void initTextField() { entryUser = (EditText) findViewById(R.id.studentEntrySalary); entryUser.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: userValidateEntry(); return true; } } return true; } }); } private void userValidateEntry() { System.out.println("user validate

Show soft keyboard for dialog

≡放荡痞女 提交于 2019-12-02 16:04:40
I am displaying a dialog with an edittext view. However, the softkeyboard will open only if the user presses inside the editview. So I tried calling an InputMethodManager with the following code. InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(dialogField,0); The dialogField is the input field. However, when exactly am I supposed to do this? I tried it in the onStart() method of the dialog, but nothing happens. I also tried requesting the focus for the dialogField before, but that changes nothing. I also tried this code dialogField

How to hide Android Soft Keyboard? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-02 13:44:07
This question already has an answer here: Close/hide the Android Soft Keyboard 96 answers I have two EditText Views and a Button in Linearlayout. After Completion of writing in the edittext, I want to hide the Android Virtual keyboard, How can I do that? Lucifer You may use the InputMethodManager class like this: InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow( yourEditText.getWindowToken(),InputMethodManager.RESULT_UNCHANGED_SHOWN); 来源: https://stackoverflow.com/questions/22404302/how-to-hide-android-soft-keyboard

ImageView resizes when keyboard open

て烟熏妆下的殇ゞ 提交于 2019-12-02 09:27:51
This is my code <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/bgImage" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:contentDescription="@string/todo" android:scaleType="fitXY" android:src="@drawable/default_wallpaper" /> <LinearLayout android:id="@+id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@

How do I make my own keyboard for an app in android?

拜拜、爱过 提交于 2019-12-02 06:32:45
问题 I am currently working on an app that requires a keyboard in a different language (Specifically Hebrew). The problem is that I don't know where to begin. I don't want the user to have to go onto an app store, and install a separate app that has more languages in it just to use my app. I only want the keyboard to be available in my app (i.e. it shouldn't effect anything outside my specific app). The way I am doing it right now is to create it as part of the main layout, and just make it

Android webview keyboard covering up input

两盒软妹~` 提交于 2019-12-02 04:55:38
The desired effect for my android application is to have a webview with an input box and content. When the user clicks on the keyboard, the keyboard pushes the input box up, but does not resize the main content and just overlays ontop of it as seen in the diagram below. The problem I'm experiencing is that the keyboard covers the input box and does not push it up. This is currently a cordova android application. In the manifest, I have configued <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode=

How to make AlertDialog view in Input method Service?

≡放荡痞女 提交于 2019-12-02 04:32:05
I would like to make an input method which is used only for SoftKeyboard. My how to make popup onkey event in input method. I am creating Dialog but here is problem you see my logcat: 09-14 11:16:54.349: E/MessageQueue-JNI(7172): at android.inputmethodservice.KeyboardView.detectAndSendKey(KeyboardView.java:824) Softkeyboard.java Here java code public void onKey(int primaryCode, int[] keyCodes) { if (primaryCode == -2) { // add this to your code dialog = builder.create(); Window window = dialog.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.token = mInputView

OnBackPressed with a SoftKeyboard open

旧巷老猫 提交于 2019-12-02 02:55:11
问题 I want to finish an activity when the soft keyboard is open, I want to override the back event of the soft keyboard and finish the activity. I'm using this but it's not working , any Idea ? public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { this.finish(); return false; } return super.dispatchKeyEvent(event); } 回答1: onKeyDown() and onBackPressed() doesn't work for this case. You have to use onKeyPreIme .