Android - EditText- selectable, uneditable - java

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"

Related

Android app - show "Change Keyboard" settings dialog

I am developing an android app in Java that needs to be set up as a keyboard.
I want to have a button that when the user presses my app shows the following dialog box:
This is a quick settings dialog box to allow the user to choose the input method (keyboard) it wants to use from now on. It is a default Android setting that is accessible to any user.
Normally this setting shows up when you press the following shortcut next to the android navigation bar when a keyboard is opened:
But in the context I am working on, this option is not visible to the user. So I want my app to be able to show this setting to the user when it presses a button.
I know an app that does this exact thing, so I know that it is possible. However, I don't know how to code a button that displays a system dialog box like this one.
Could you please help me?
Thanks in advance!
After some more research I found the answer using an InputMethodManager object and the showInputMethodPicker() method in Java:
InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.showInputMethodPicker();

Android, how to show software keyboard on click

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 it possible to hide the keyboard with a button?

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...

How to use android soft keyboard in SurfaceView

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

Why doesn't the virtual keyboard go away?

I have a pretty simple screen with a couple of EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard comes up. However, I can't seem to get rid of it. Clicking on an empty space on the screen does not make it go away. Only clicking the virtual Return key or the hardware Back button makes it disappear.
I don't have a real Android phone handy, so is this an emulator only thing or will it be like this on the actual device. If it is, what can I do to make the virtual keyboard go away, when I click elsewhere on the form?
Click the back button. They keyboard is an activity. There's not an easy way to remove the keyboard when clicking on a random area of the screen.
AngryHacker , I woud refer you to this post how to close/hide the android soft keyboard.
Hope this helps.
I think in the emulator you can press Escape to hide the keyboard. On a real device there is a hide button on the keyboard or you can press elsewhere in the ui. That's how it works on my HTC Desire S anyway.
I lived this problem and i resolved it. This problem is about InputMethodManager.SHOW_FORCED value in my project. When i open keypad using SHOW_FORCEDthen when i try to close keypad, keypad was not closing.
For Example :
activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_FORCED);
If you use above way to open keypad, you may try to change SHOW_FORCED value with SHOW_IMPLICIT value
For Example :
activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
I have the Galaxy S2 which is running Andriod 2.3.6.
I was having issues with the keyboard not moving out of the way after entering the needed text when logging into websites. I found that hitting the hardware return button does take the virtual keyboard out of the way. But occassionally it will take the web browser back one page. Which is frustrating because then I have to re-enter the log in info for whatever web site I'm connecting too. Hopefully Android 4.x has solved some of these glitchy issues.
You can achieve this by doing the following steps:
Make the parent view(content view of your activity) clickable and focusable by adding the following attributes
android:clickable="true"
android:focusableInTouchMode="true"
Implement a hideKeyboard() method
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
}
Lastly, set the onFocusChangeListener of your edittext.
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
Source

Categories

Resources