boolean showSoftInput(View view, int flags, ResultReceiver resultReceiver) boolean showSoftInput(View view, int flags) void showSoftInputFromInputMethod(IBinder token, int flags)public void toggleSoftInput (int showFlags, int hideFlags) public void toggleSoftInputFromWindow (IBinder windowToken, int showFlags, int hideFlags)但是上面InputMethodManager的方法在oncreate(),和onResume()中調用會沒有作用。

  留意:可能是由於View還沒有預備好,所以不起作用。網上找來的理由說是:軟體盤是要在所有view畫完才能顯示。

  可以採用timer或Handler延遲在執行。Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { InputMethodManager imm = (InputMethodManager)vv.getContext().getSystemServi ce(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);Toast.makeText(test.this, "show", Toast.LENGTH_SHORT).show(); } }, 1000);

  調用InputMethodManager的以下方法可以封閉軟鍵盤

  void hideSoftInputFromInputMethod(IBinder token, int flags)

  Close/hide the input method’s soft input area, so the user no longer sees it or can interact with it.

  boolean hideSoftInputFromWindow(IBinder windowToken, int flags)

  Synonym for {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

  boolean hideSoftInputFromWindow(IBinder windowToken, int flags, ResultReceiver resultReceiver)

  Request to hide the soft input window from the context of the window that is currently accepting input.

  留意:封閉鍵盤的時候不再可以像開啟一樣傳遞View,而必須是View的IBinder,可以通過View的getWindowToken()得到相應的IBinder。

  Eidtext可以自己自動地彈出軟鍵盤

  Eidtext這個控制項預設是你點擊了它獲得焦點之後假如軟鍵盤還沒打開就會自動地彈出軟鍵盤。

  條件是你在豎屏的時候。但橫盤的時候,不會自轉動出彈出軟鍵盤了。

  留意:這種情況下,Eidtext在這次事件中就不再進行游標定位的處理。

  manifest中對軟鍵盤彈出的屬性進行設置

  可以在activity的android:windowSoftInputMode屬性進行設置 android:windowSoftInputMode

  How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:

  * The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.

  * The adjustment made to the activity’s main window — whether it is resized smaller to make room for the soft keyboard or

  whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

  The setting must be one of the values listed in the following table, or a combination of one “state…” value plus one “adjust…” value.

  Setting multiple values in either group — multiple “state…” values, for example — has undefined results.Individual values are separated by a vertical bar (|). For example:

  Values set here (other than “stateUnspecified” and “adjustUnspecified”) override values set in the theme.

  Value Description

  “stateUnspecified” The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

  This is the default setting for the behavior of the soft keyboard.

  “stateUnchanged” The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.

  “stateHidden” The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

  “stateAlwaysHidden” The soft keyboard is always hidden when the activity’s main window has input focus.

  “stateVisible” The soft keyboard is visible when that’s normally appropriate (when the user is navigating forward to the activity’s main window).

  “stateAlwaysVisible” The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.

  “adjustUnspecified” It is unspecified whether the activity’s main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the currentfocus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window’s contents visible within a smaller area.

  This is the default setting for the behavior of the main window.

  “adjustResize” The activity’s main window is always resized to make room for the soft keyboard on screen.

  這個可以讓view自己調整大小以便顯示軟鍵盤http://www.secure-engine.org/。CMMI評估這樣的話控制項可能會變形。

  “adjustPan” The activity’s main window is not resized to make room for the soft keyboard.
 
 Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.

  This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

  這種方式是通過調整view的空缺區域來顯示軟鍵盤。即使調整空缺區域,軟鍵盤還是有可能遮擋一些有內容區域。這樣的話使用者就只有退出軟鍵盤才能看到這些被遮擋區域並進行交互。

  官方相關文檔位址:http://developer.android.com/guide/topics/manifest /activity-element.html#wsoft

  如何監聽軟鍵盤是否打開?

  到目前為止還沒找到監聽軟鍵盤是否被開啟的方法。

  網上建議用onConfigurationChanged (Configuration newConfig)的來對Configuration的keyboardHidden來監聽的方法在三星的手機上也無效。

  public int keyboardHidden

  Since: API Level 1

  A flag indicating whether any keyboard is available.

  Unlike hardKeyboardHidden, this also takes into account a soft keyboard,

  so if the hard keyboard is hidden but there is soft keyboard available, it will be set to NO.

  Value is one of: KEYBOARDHIDDEN_NO, KEYBOARDHIDDEN_YES.

  原文連結:http://hubingforever.blog.163.com/blog/static/1710 /
http://m8fq6ae0qc.blog.163.com/blog/static/18628923820117283517740
 
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()