Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a few imeOptions programmatically

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

like image 362
kazhiu Avatar asked Apr 25 '14 23:04

kazhiu


People also ask

How do I change the focus to next text in android?

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; } });

What is imeOptions?

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.

How do I change the Done button on my android phone keyboard?

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.

What is inputType in android?

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.


1 Answers

Try like as below.

editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
like image 102
Karthikeyan Avatar answered Oct 20 '22 18:10

Karthikeyan