Solution to the problem of not popping up the soft keyboard when Android enters the page

Here we just record one of the problems that the soft keyboard does not pop up automatically when entering the page. There may be other reasons that cause the pop-up to fail.

Cause number one

Enter the page and directly write the method of popping up the software disk. At this time, because the system UI interface has not been loaded, the keyboard popup operation will be performed, causing the popup to fail. Here, only the price is delayed.

Timer timer = new Timer(); //设置定时器
timer.schedule(new TimerTask() {
    
    
    @Override
    public void run() {
    
     //弹出软键盘的代码
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(searchText, InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
}, 50); //设置50毫秒的时长

Other reasons to be added later

Guess you like

Origin blog.csdn.net/nanjumufeng/article/details/130084994