Android keyboard - android

My application starts with a bunch of text input fields, and I want that when starting up the the application. The virtual keyboard isn't open, but opens only when I click on one of the textinput fields.
How do I do this?

In your onCreate method you could get your first text view and call requestFocus() on it. This ought to focus this field when the activity starts and bring up a virtual keyboard if needed.
If you want the keyboard not to appear on startup, request focus for a non-text element like a button.

You should leave the input method to the user. They might be using a physical keyboard or maybe even something like speech to text.

I've used this approach to hide the keyboard after the user searches. You could use this in our onCreate method:
Close/hide the Android Soft Keyboard
Quote from Reto Meier's accepted solution:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Related

Getting keystrokes from the soft keyboard from within a fragment

I have an activity that launches a fragment whose main purpose is to present the user with an Imagebutton that they can click to launch the soft keyboard and type in whatever text they like. I need to grab each key as it is pressed on the soft keyboard. However, the user is not typing into an EditText view so I am struggling a bit with this. I can successfully display the soft keyboard when the user clicks the ImageButton using the code below...
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
However, I have not been able to find an example or a method that would let me grab the keystrokes from the soft keyboard without an EditText. I assume this must be possible I just don't know how to go about it.
Maybe it helps if you implement your own InputMethodService? You can overwrite the onUpdateSelection() method, which is called every time when a key is touched on the softkeyboard.

Keyboard doesn't show up when EditText is in focus

I want to do the following.
User should be able to input one letter (only letter) from standard keyboard (hardware or software). If he is typing another letter, then the previous letter should be replaced with this one. So only the current letter should be displayed. User should be able to dismiss this dialog and get back to activity. And if he clicked "done" button in keyboard the activity should know what letter he entered.
So I thought about alert dialog and edit text with some extensions to display only current char. This is easy.
However, and this gets me mad already, although edit text is in focus the keyboard does not appear on the screen until edit text is clicked. Why is that so?
It should be, should it not?
I won't take something like the following for the answer, because I shouldn't have to do it manually. It should be automatic. Besides, I'm not sure how this would work with a hardware keyboard.
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(YourEditText.getWindowToken(), 0);
I want to know why exactly the keyboard is not shown after edit text has focus?
And what should I do to get this functionality without manually enabling and disabling software keyboard.
Use this.
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
For your information, see this related question: Why the soft keyboard shows or not when an activity starts?. You can read it as an alternative by enclosing your EditText into a ScrollView.
But it's not more satisfying than the well known workaround (manually enabling the software keyboard) because we don't understand why it works better in this case...

Set android focus on touch?

I have this issue: in my app, when user taps on EditText bar, keyboard pops up. After that, it is impossible to get rid of keyboard. When back button is pressed, whole application just turn off.
How can I make sure, that when user taps on some other object (not EditText), keyboard will be removed? Or at least, how to make it possible to hide keyboard by tapping back button?
Thanks.
in xml for EditText this will make keyboard dismiss when press enter on keyboard
android:imeOptions="actionDone"
You can hide the keyboard simple by overriding onBackPressed in your Activity and using the following code:
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(anyView.getWindowToken(), 0);
Note that anyView can be any view that is attached to your current window.
You can see it working in my app called Magic Annotator. See method hideSoftKeyboard()

Android onscreen keyboard without any other keyboard

I've looked at several questions and come across several posts, but i'm not able to figure out how to do this.
The following picture shows you the basic layout :
I've created a custom numpad and put it up on the repo.
Currently, when the app opens, the edit text has the focus but and anything i enter with the keyboard will go into the edittext box. This part of the functionality works fine.
Problem: When i touch the edittext again, system Input Method with its huge keyboard pops up. How do i completely block it from popping up? Or, can i tell the app to use only my keyboard instead of the system one? (Or is the only way to write a custom ime?)
i cannot use NULL type input at the manifest because doing that makes the caret in the edittext disappear and moreover if there are two edit texts, i wouldnt know which has focus.
Any help would be highly appreciated!
You can do a few things:
Programmatically hide it in the whole app:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hide it from the view it would be attached to:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
Set the input type of the EditText to 0:
EditText yourEditText=(EditText)findViewById(R.id.editTextConvertValue);
yourEditText.setInputType(0);

Forcefully bring android soft keyboard without any edit fields

I know we can bring the soft keyboard in android with any edit fields. I need to know whether it is possible to bring soft keyboard without any edit fields such as, on click of a button.
On click of a button, I need to bring the soft keyboard and monitor the key press events. Is there a way to bring soft keyboard on click of button?
well, the standard way of bringing up the soft keyboard is
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);
However, I've always used it to bring it up in conjunction with a EditText component. But I believe if you put that code in the click listener for the button, the keyboard should show up.
Try this
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.showSoftInput(View youredittextobject, InputMethodManager.SHOW_FORCED)
In above code the first argument is of the edittext object view that you need to pass for which you want the keyboard to show up

Categories

Resources