簡體   English   中英

在焦點更改時顯示軟鍵盤EditText Android

[英]Showing softkeyboard on change in focus edittext android

當焦點改變時,我正在使用下面的代碼顯示編輯框的鍵盤。

  no1.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
            if(keyCode == 66) {

                no2.requestFocus();

            }
            }
            return false;
        }
    });


    no2.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
            if(keyCode == 66) {
                 //Log.e("I am inside no2","no2");
                no3.requestFocus();

                return true;


            }
            }
            return false;
        }
    });



    no2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
               Log.e("In","Innnnnn");
               InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(no2, InputMethodManager.SHOW_IMPLICIT);         
            }
        }
    });

但是,鍵盤不顯示。 正在打印日志語句。 因此,這意味着它正在進入focusChanged方法。 有什么想法我做錯了嗎?

使用InputMethodManager控制鍵盤。

嘗試這個...

final AlertDialog dialog = ...;

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

嘗試這個

InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM