I have a SurfaceView that I draw onto, there are no controls, text boxes or any other sort of form-type item. I would like to be able to :
1: Touch one of the circles I draw on the SurfaceView onDraw() method and open the default android soft keyboard. (I know how to do the touch detection part, just need to open the soft keyboard somehow)
2: As I type I want the letters I select to be shown on the canvas (Again I know how to do the drawing part, but how do I capture the keys the user has selected in the first place?)
many tanks
David
you can try this to show the keyboard:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
if that shows it for you then I imagine you could listen for the key events by overriding the onKeyDown() method of your activity
Related
I am trying to hide a numbers keyboard programmatically with java and I used this code in a onClick of a button
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
But as a result when the user click the first time the numbers keyboard become strings keyboard (normal keyboard) and when the user click the 2nd time the keyboard hides.
I want the keyboard get hide from the first click, any help ?
Try this code for hiding keyboard:
/*--for hiding keyboard on click--*/
InputMethodManager imm=(InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view3=getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view3==null){
view3=new View(this);
}
assert imm != null;
imm.hideSoftInputFromWindow(view3.getWindowToken(), 0);
I have been developing a simple Calculator Application in Android Studio.
The result window (where the numbers are placed for calculation) I initially set as a TextView. However, I haven't found a way to implement a cursor while using the TextView. My goal is to have the result window display a cursor and have text selectable but not editable. When using EditView I have tried to disable the soft keyboard, disable input, etc., with no success. Can I accomplish this using either an EditView/TextView?
Soft keyboard issue
Screenshot
I obviously do not want the user to be able to utilize the soft keyboard, but I still want to maintain the cursor and have the text selectable.
To hide keyboard keys in fragment interface use
EditText edt=(EditText)View.findViewById(R.id.editTextForNumbers);
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt.getWindowToken(), 0);
If it is in an activity use
EditText edt=(EditText)findViewById(R.id.editTextForNumbers);
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edt.getWindowToken(), 0);
Set these properties for your edittext or textview
android:cursorVisible="true"
android:textCursorDrawable="#null"
I have a dialog box in my Android app; it is the only EditText control on the dialog (the others are spinners and buttons), and so it gets focus when the dialog is shown. This prevents the on-screen keyboard from ever showing up, meaning you can't easily enter any text into the box unless you have a hardware keyboard.
I believe (but I couldn't swear to it) that this is because the control starts with focus, and the system check as to whether to show the keyboard or not happens in the onfocus event. Is there any way the programmatically show the on-screen keyboard?
In order to implement the ability to force the keyboard open when the user presses a button on the screen then the following should help.
InputMethodManager inputMethManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
However an alternative to help regain focus of the dialog window can be found below. This code should open the software keyboard for you by resetting any flags initially set by AlertDialog. This code should be placed after the creation of the dialog window.
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Is there any way to show or hide the soft keyboard instantly, without any animation? In Cyanogenmod 10 it displays with a fading animation.
try like this
InputMethodManager imm = (InputMethodManager)getSystemService(Context.
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0);
In my app, I have a Tab system, and in one of the tab layouts, there is an EditText.
And if I go to a different tab, the keyboard stays up.
So I've added a button that would hide it:
So how do I set the Button to closing the keyboard? It would also be very helpful if the keyboard went away when switching tabs.
private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getTabHost().getApplicationWindowToken(), 0);
}
This method hides the keyboard. Works in tab case. Just set on the each tab the same OnClickListener, which calls hideKeyboard().
What i've done in my app is try and not use a button to close the softkeyboard cause i'm already using a button, instead of your Done, called Del whcih empties out the EditText field. What i've done is on the first press of the EditText show the keyboard, and at a second press just hide it.
Try using this in the onClick callback function for the EditText, OR if you want to keep the Submit button, then add this on it's onClick listener and for every tab you have as well.
InputMethodManager keyboard = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Hope this helps, cheers.
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
add these to the event when you want to hide soft keyboard...