<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                > 編寫:[zhaochunqi](https://github.com/zhaochunqi) - 原文:[http://developer.android.com/training/keyboard-input/visibility.html](http://developer.android.com/training/keyboard-input/visibility.html) 當輸入焦點移入或移出可編輯當文本域時,Android會相應的顯示或隱藏輸入法(如屏幕輸入法)。系統也會決定你的輸入法上方UI和文本域的顯示。舉例來說,當屏幕上豎直空間被壓縮時,文本域可能填充所有的輸入法上方的空間。對于多數的應用來說,這些默認的行為基本就足夠了。 然而,在一些事例中,你可能會想要更加直接的控制輸入法的顯示,指定你的布局在在輸入法顯示時候的表現。這節課會向你解釋如何控制和回應輸入法的可見性。 ### 在[Activity](# "An activity represents a single screen with a user interface.")啟動時顯示輸入法 盡管Android會在[Activity](# "An activity represents a single screen with a user interface.")啟動時給予第一個文本域焦點,但是并不會顯示輸入法。因為進入文本可能并不是[activity](# "An activity represents a single screen with a user interface.")中的首要任務,所以這為是很合理的。可是,如果進入文本確實需要是首要的任務(如登錄界面),可能需要用到輸入法默認顯示。 為了在[activity](# "An activity represents a single screen with a user interface.")啟動時展示輸入法,添加[android:windowSoftInputMode](http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft) 屬性到<[activity](# "An activity represents a single screen with a user interface.")>元素中,使用 "stateVisible",如下: ~~~ <application ... > <activity android:windowSoftInputMode="stateVisible" ... > ... </activity> ... </application> ~~~ > **注意:**如果用戶設備有一個實體鍵盤,軟鍵盤輸入法可能不顯示。 ### 需要時顯示輸入法 如果在[activity](# "An activity represents a single screen with a user interface.")生命周期中有一個方法在想要確保輸入法是可見的,可以使用 [InputMethodManager](http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html) 來實現。 舉例來說,下面的方法調用了一個需要用戶填寫文本的[View](http://developer.android.com/reference/android/view/View.html),調用了[requestFocus()](http://developer.android.com/reference/android/view/View.html#requestFocus()) 來獲取焦點,然后 [showSoftInput()](http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#showSoftInput(android.view.View, int))來打開輸入法。 ~~~ public void showSoftKeyboard(View view) { if (view.requestFocus()) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } } ~~~ > **注意:**一旦輸入法設定可見了,你不應該用程序來隱藏。系統會在用戶結束文本域的任務的時候隱藏,或者可以使用系統控制(如返回鍵)來隱藏。 ### 指定你的UI回應方式 當你的輸入法顯示在屏幕上,減少了UI中的可用空間。系統會為你的UI的可見區的UI做調整但是可能并非很正確。為了確保你應用的最佳表現,你應該在UI的剩余空間中展示你想要展示的系統界面。 為了聲明你在[activity](# "An activity represents a single screen with a user interface.")中的合適的對待,使用 android:windowSoftInputMode 屬性在你的清單文件中的<[activity](# "An activity represents a single screen with a user interface.")>元素使用某個"adjust"值。 舉例來說,為了確保系統會在可用空間中重新調整布局的大小。為了確保你所有的布局內容都是可用的(盡管可能需要滑動)使用"adjustResize": ~~~ <application ... > <activity android:windowSoftInputMode="adjustResize" ... > ... </activity> ... </application> ~~~ 你可以結合調整和使用上面的[初始輸入法可見性](#)來指定: ~~~ <activity android:windowSoftInputMode="stateVisible|adjustResize" ... > ... </activity> ~~~ 如果你的UI中包含用戶可能需要在文本輸入時立即執行的事情,那么使用"adjustResize"時很重要的。例如,如果你使用相對布局在屏幕底部放置一個按鈕,使用"adjustResize"來重新調整大小,使得按鈕欄出現在輸入法上方。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看