I'd like to highlight the text in an EditText when a keyboard opens for user input (this could be a hardware keyboard or the virtual keyboard).
Highlighting isn't my problem, my problem is a trigger to highlight. Is there a handler that gets executed when the keyboard appears on a specific View (in this case, my EditText)? Are there different handlers for hardware keyboard vs virtual keyboard?
As far as I know, you can't get notified of those things at that level. Why not just highlight it when the EditText gets focus? In practice this will generally mean that an IME is displayed.
In fact, there is already a method to do exactly this: setSelectAllOnFocus.
Related
Is there any way to enable onFocus, onBlur etc. on Touchable-Elements on non-TVs devices?
The touchable elements event is not triggered, but the default feedback is visible when I use the physical keyboard.
I need simple dialogs on a Zebra mc3300. This device has a physical keyboard and when I show a dialog with a yes/no question, one button should have focus when the dialog becomes visible.
I'm not sure, maybe ref.current?.focus() works, when I press enter the key onPress is triggered, but i don't get any visible feedback which key has the focus. Only when I use the hardware button to switch to the next element and back again, the button became a different opacity.
Many thanks to you.
Previously I had a problem to do with soft keyboard backspace on Android 4.4.3 and this only occurs on the device that uses the Android Keyboard (AOSP).
Backspace seems to not work when the view is currently in focus on a text box and when I tap on the right of the entered text in the text box, sometime backspace becomes disabled and you can't get it to work without having to refocus on the text box again.
But I seem to fix the issue by overriding the deleteSurroundingText() in my CustomInputConnection class as suggested in this post (Android: Backspace in WebView/BaseInputConnection) However, I discovered a problem which is caused by overriding the onCreateInputConnection method in the WebView, for some reason when putting focus on to an element with an input type set to number, it displays a Qwerty Keyboard rather than a number keyboard.
Any suggestions to why this is happening is much appreciated.
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 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).
I've got an Android application I'm writing. It has a ListActivity in it that's all set up to load my data using this layout for each item.
My data Adapter binds with no problem and I've set it up so that when an item is selected from the list this method is called.
private void showPasswordBox(View v) {
EditText passwordBox = (EditText)v.findViewById(R.id.hidden_box);
Button passwordSubmit = (Button)v.findViewById(R.id.hidden_box_submit);
passwordSubmit.setText("Login");
passwordSubmit.setVisibility(View.VISIBLE);
passwordBox.setFocusableInTouchMode(true);
passwordBox.setHint(R.string.password);
passwordBox.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordBox.setVisibility(View.VISIBLE);
}
This has the effect of displaying and EditText and a Button (hidden_box and hidden_box_submit in my layout). Which is just what I wanted.
However a problem occurs when the user taps on the newly visible EditText (hidden_box). The IME pops up and hidden_box immediately loses focus. Consequently anything typed on the IME does not appear in the EditText. Instead it's doing this weird thing where anything typed appears above the keyboard in grey letters and remains at the bottom of the screen when the IME is dismissed. It's like the IME is typing into it's own temporary invisible box.
If the user taps on the EditText after the IME is already showing then the application behaves as it should. Anything typed on the IME appears in the EditText and remains when the IME is dismissed.
It seems to me that when the IME pops up (which it does immediately when the user taps on the EditText, as it should) it completely de-associates with my application and does its thing in IME la-la land unless I direct it to the EditText by tapping on the EditText before typing and dismissing the keyboard. How do I make it behave normally so it types directly into the EditText as soon as it pops up?
passwordBox.setFocusableInTouchMode(true);
Hope this will work. Does it?