關於Android程序彈出軟鍵盤的問題

鍵盤彈出的代碼
        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);
                inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }, 2000);
用以上的代碼軟鍵盤一直不能彈出,必須在AndroidManifest.xml中加入     <activity
           android:windowSoftInputMode="stateVisible|adjustPan" >
才能顯示軟鍵盤,timer對象能夠延遲鍵盤彈出的時間。android

相關文章
相關標籤/搜索