I have FrameLayout
container in which I want to add dynamically EditText
. I need to set two imeOptions
: IME_ACTION_DONE
and IME_FLAG_NO_EXTRACT_UI
in this same time but I have problem how to do it programmatically. My solution override my imeOptions
(I now that is good behavior :) but I try everything)
And my secound question: How to set focus after create EditText programmatically? This method editText.requestFocus();
dosen't work for me. I want to open keyboard after postCardContainer.addView(editText);
postCardContainer.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = (int) event.getY()-50;
params.leftMargin = (int) event.getX()-50;
EditText editText = new EditText(NewPostcardActivity.this);
editText.setSingleLine();
editText.setBackgroundResource(R.color.transparent);
editText.requestFocus();
editText.setLayoutParams(params);
editText.setCursorVisible(true);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
postCardContainer.addView(editText);
return false;
}
});
Thanks
setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (edtPasscode3. getText(). length() == 1) edtPasscode4. requestFocus(); return false; } });
android:imeOptions can set the text/id of the button displayed near the space key to some pre-defined values (E.g. actionGo set the key label to Go and the id to 2) android:imeActionLabel set the label of the button displayed inside the input area when the keyboard is fullscreen, usually in landscape mode.
If you want the kb to hide when clicking Done , and you set android:imeOptions="actionDone" & android:maxLines="1" without setting your EditText inputType it will NOT work as the default inputType for the EditText is not "text" as a lot of people think.
The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.
Try like as below.
editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With