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);
Related
I have an application where I needed to create a custom keyboard since barcode scanners are classified as hardware keyboards and hardware keyboards disable soft keyboards. The issue is that when no scanner is connected, the built in soft keyboard will be displayed when it's not needed. I have a button to show the custom keyboard which will also hide the default keyboard using
((InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(advText.getWindowToken(), 0);
(advText is an extended version of EditText)
I have tried placing that line of code in the onFocusChanged method of the EditText but nothing happens. If I use setInputType(InputType.TYPE_NULL); the android keyboard never shows, but the EditText doesn't display a cursor or anything that is typed from the custom keyboard (but I do know that keys are being stored since my "done" key sends the text from the EditText elsewhere just fine).
I'm fine with disabling the android keyboard completely for this app, just as long as the EditTexts show cursors and custom keyboard is only shown when using the button.
I have looked at these answers, but no luck finding a solution.
Close/hide the Android Soft Keyboard
How to show soft-keyboard when edittext is focused
How to hide Android soft keyboard on EditText
Edit:
My current solution is to run the hide method inside of the EditText's onCheckIsTextEditor since that seems to run after onFocusChanged, and it seems to be called about every second. But this is a nasty hack since the keyboard still shows for a split second and moves my layouts back and forth. My current test devices consist of the Motorola Photon Q 4G LTE with 4.1.2 and a Honeywell Dolphin 70e Black with 4.0.3
EditText provides this functionality with the flag textIsSelectable in EditText set to true. With this, the cursor will still be present, and you'll be able to select/copy/cut/paste, but SoftKeyboard will never show. Requires API 11 and above.
You can set it in your xml layout like this:
<EditText
...
android:textIsSelectable="true"/>
Or programmatically, like this:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
For anyone using API 10 and below, hack is provided here :
https://stackoverflow.com/a/20173020/7550472
Edit your <activity> tag in your AndroidManifest.xml and add this attribute: android:windowSoftInputMode="stateAlwaysHidden" see http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Just added that and remove all the other weird things you are doing to hide the soft keyboard.
P.S. You can also enable and disable this feature at runtime. getWindow().getAttributes().softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
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...
Hi friends,
I am working on an android application. I have a small issue with
android soft keyboard. I have an editText and when i click on it, it
shows me android soft keyboard. On the top of the soft keyboard, there
is a text area that displays all the text i type using soft
keyboard.It displays me what ever text i type using the keyboard. Is
there a option to hide that text area on keyboard.
Kindly help me in this issue.
Thanks in advance.
I think you are talking about Auto Suggestion. Add the following code to your edit text in the layout file.
android:inputType="textNoSuggestions"
or in the code, you can use it like this,
setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
also you'd better read this
Solution if you speak about auto-focus on edittext:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
you can also use EditText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
in your code.With the following code,one can stop the suggestions coming automatically from soft keyboard when you click on EditText
In my application, I have a search button which when clicked will make an EditText widget visible, put focus in it, and show the keyboard. When I do this I call this code:
queryTextView.requestFocus();
InputMethodManager imm = Utilities.getInputMethodManagerFromContext(getContext());
imm.showSoftInput(queryTextView, InputMethodManager.SHOW_FORCED);
The first time this shows as I expect it to in landscape:
Once I enter text and hit search, I will hide my EditText and force the keyboard closed. I do this using this code:
InputMethodManager imm = Utilities.getInputMethodManagerFromContext(getContext());
imm.hideSoftInputFromWindow(getWindowToken(), 0);
If I were to hit my button again to make the EdidText visible and show the keyboard again, my screen looks like this (only when using the stock Galaxy Nexus keyboard):
Using another keyboard, such as SwiftKey, I do not get this behavior. What kinds of things can I look for to find out why this soft-keyboard is not filling the screen fully?
EDIT: on second thought, from your screenshots it looks like the keyboard is trying to take up the full screen, so onEvaluateFullscreenMode should be returning true...perhaps the problem is somewhere in onCreateExtractTextView
Not what you're looking for, but if all else fails perhaps you could grap the AOSP keyboard source, walk through it and figure out if/why onEvaluateFullscreenMode is returning, or maybe it isn't being called at all.
Use android:imeOptions="flagNoFullscreen" to achieve that feature.
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);