I making an application with my own keyboard and I want to completely DISABLE the android default virtual keyboard.
I tried this:
myEditText.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(keresetEditText.getWindowToken(), 0);
}
});
It is working very well, but accidently I just found an error that really bugs me to the hell:
When I slide down my finger on the EditText the soft keyboard just appear!
So the conclusion is: the onClickListener just not running while i slide, and not tap.
I tried onTouchListener, but it just didn't work!
Any tips how could I completely disable virtual keyboard ? I don't need it in the entire application.
Other thing:
I could make an other question to stackoverflow but I think its logical here so:
When I click on the EditText's cursor, i can move it in the text inside my EditText, but i dont want it to enabled like this. Can I disable the cursors MOVEability ??? So i need the blinking cursor but just totally in stayed position.
Here are few solutions for you:
if you will never need the softkeyboard to show on that activity, you can set the android:windowSoftInputMode="stateAlwaysHidden" attribute in manifest
disable the edit text. You will not have the blinking cursor (or any cursor at all), but it will be impossible to open the soft keyboard using a disabled edit text, while still being able to set your own text in code
just use a TextView, while setting as background android.R.drawable.edit_text .It will look like an EditText, while only being a read-only TextView, still allowing you to set any value from code. Again, you still don't have the blinking cursor
set the EditText's focusable and clickable attributes to false. The edit text will never receive focus, thus never causing the soft keyboard to show
(this is a hack) place an invisible button over the edittext, so a click over the edittext will actually be intercepted by the button that does nothing. The edit text will still be focusable using the trackball or direction keys, and you still won't have the blinking cursor
Related
I want the user to enter data in an EditText using a custom keypad. The custom keypad is integrated to the layout. It is not supposed to pop up when the EditText in question is in focus.
The problem I have is that I can't disable the soft keyboard without disabling the editing properties of the EditText: I want the user to be able to position the cursor for example.
I have tried using the InputMethodManager
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
but it doesn't work at least on some OS versions. The keyboard still pops up when I tap the EditText.
I have also tried setting the input mode:
edtView.setInputType(0)
but then I cannot position a cursor. I could Selection.setSelection(Spannable txt, int index); to position the cursor, but how to know the position the user has touched?
I never tried this myself, but the only thing that occurs to me is: have you tried adding an OnEditorActionListener to your EditText and calling hideSoftInputFromWindow every time you get an editor action?
Is there a way to detect when the keyboard is about to be presented in Android?
My problem is that I have a ListView with EditTexts in it. When the keyboard is about to be presented, these are quite often redrawn, causing an EditText that was JUST tapped to lose focus and require an extra tap.
My proposed solution is to monitor when the keyboard is about to be shown, check to see which view currently has focus, then after the keyboard is done being shown, restore focus to that view.
However, I have no idea how to detect when the keyboard is "about to be shown" in Android. How would I do this?
(I would also accept an alternative answer that addresses my actual problem: EditText losing focus when keyboard is displayed)
You could do it the other way, create an unique OnFocusChangedListener myListener and set it to all your EditTexts and put a switch inside and store which is the last view getting/losing focus
I want an EditText to lose focus the moment the user touches other UI elements in the Activity like check boxes or really touches anywhere outside the EditText within the Activity, but this is not happening. The focus only gets changed when the user starts typing into another EditText. Not for example when they click on an Checkbox or when they click on other areas of the screen.
It sounds like you need to add the following two lines to all of the widgets in your layout:
android:focusable="true"
android:focusableInTouchMode="true"
That way they can all receive focus (normally only certain ones can) and you can attach onFocusChangeListener to the EditText in question and you should achieve the desired results.
Of course, this could also play havoc with your other widgets (not knowing what they are I can't be certain), but it's worth a shot.
Could you not just force close the android soft keyboard on click event of another View?
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
The toggle call literally does just that - if its open, it will close, if its closed, it will open!
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);
I have a common EditText. It's very strange because I can't focus it when use hard keyboard. Context condition:
switch Droid's hardkeyboard on
start the activity
click the editText to input
Fail to input. When you press any key, the editText lost focus.
To get focus:
press Dpad and you will see the focus starts from the 1st widget in the screen. And finally focus on the target EditText. Then you can input. Without this, you can't input with hard keyboard at all.
Soft keyboard doesn't have such focus problem.
I am using android 2.2. Is this a system bug?
As mentioned above this is clearly a bug with hard keyboard. If you have an EditText and a TabHost in your layout, on first key pressed, EditText lose focus and key press is sent to the activity instead. Here is a work around to this problem. Implement this in your activity.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event){
final EditText myInputField = (EditText) findViewById(R.id.MyInputEditText);
// this will happen on first key pressed on hard-keyboard only. Once myInputField
// gets the focus again, it will automatically receive further key presses.
if (!myInputField.hasFocus()){
myInputField.requestFocus();
myInputField.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
if you have multiple EditText fields, you will need to keep track of currently focused EditText in a class variable and use it in onKeyDown method.
I have the same problem. I kinda agree with Jay. Typically TabHost, and/or TabActivity utilize a LocalActivityManager that keeps track of embedded Activities or appropriate ContentStrategy component that is displayed within the FrameLayout element. In simple words, this is a typical embedded Activities/ embedded Views layout problem. The Edit Text is on the top-most Activity/View that is taking the touch-screen space, while there's a core Activity that is actually hosting this Activity/View that probably is grabbing the InputMethodService focus and keeping it away from the Edit Text, only for the hard-keyboard scenario. The soft-keyboard just works fine.
One change I did to my Edit Text is to change the InputType as purely decimal. So when the Edit Text gains focus, the soft keyboard shows a numeric key-pad and not the alphabetical qwerty key-pad. I ran it on a Motorla Droid Pro emulator, that I updated in Eclipse Plugins from the Motodev website. Apparently, when I try to enter text from the hard keyboard after having given focus for the Edit Text (and the soft-keyboard is showing a numeric key-pad), after I click 'ALT + 2', the soft-keyboard is reloaded as alphabetic key-pad while the Edit Text loses focus entirely.
Seems like a serious bug to me in the Froyo release, insufficient support for hard-keyboard devices for edit text views in layouts (LinearLayout) that are embedded in other layouts (FrameLayout of a TabHost).