技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

Android之軟鍵盤自動彈出和關(guān)閉代碼

來源:技術(shù)員聯(lián)盟┆發(fā)布時間:2017-11-09 06:40┆點擊:

  一:軟鍵盤自動彈出。

  private EditText top_middle;//輸入框

  //-------------------------------------彈出軟鍵盤-----------------------------------

  top_middle.setFocusable(true);

  top_middle.setFocusableInTouchMode(true);

  top_middle.requestFocus();

  InputMethodManager inputManager =

  (InputMethodManager) top_middle.getContext().getSystemService(

  Context.INPUT_METHOD_SERVICE);

  inputManager.showSoftInput(top_middle, 0);

  Timer timer = new Timer();

  timer.schedule(new TimerTask()

  {

  public void run()

  {

  InputMethodManager inputManager =

  (InputMethodManager) top_middle.getContext().getSystemService(

  Context.INPUT_METHOD_SERVICE);

  inputManager.showSoftInput(top_middle, 0);

  }

  },

  998);

  二:軟鍵盤自動關(guān)閉。

  //-----------------------------------軟鍵盤自動關(guān)閉----------------------------------------

  InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);

  imm.hideSoftInputFromWindow(top_middle.getWindowToken(), 0);

  三:對話框中軟鍵盤自動彈出和關(guān)閉。

  //--------------------------------對話框中自動彈出和關(guān)閉-----------------------------------

  getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);