David.Ko

          Follow my heart!
          posts - 100, comments - 11, trackbacks - 0, articles - 0
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          android滑動鍵盤事件捕獲

          Posted on 2010-06-21 21:18 David.Ko 閱讀(1643) 評論(0)  編輯  收藏 所屬分類: Android

          G1帶有實體鍵盤,可以側推。雖然如今的G2 G3去掉了實體鍵盤,但同志們開發的應用還是得兼容一下G1吧。先從幾個問題入手:
          1、不管鍵盤是否滑出,都要設置屏幕為豎屏或者橫屏。這個該怎么處理?
          2、當用戶在豎屏狀態下編輯了一個文本框,又突然想推出實體鍵盤進行編輯,而此時Activity重繪,文本框內未保存的信息又該怎么辦?
          3、監聽鍵盤滑動事件。讓縱橫屏狀態下載入不同的layout。

          當然你也許可以再java代碼中去設置很多事件捕獲,但有一個更好的方法,那就是修改Androidmanifest.xml.

          默認的情況下推出或縮進鍵盤會重新啟動activity
          要不關閉activity 則可以在manifest.xml中增加 android:configChanges=”keyboardHidden|orientation
          然后重載public void onConfigurationChanged(Configuration newConfig) 函數
          鍵盤被抽出后會首先調用onConfigurationChanged

          如果你希望滑動鍵盤不改變屏幕分辨率 則可以增加屬性:android:screenOrientation=”portrait>
          portrait :豎   
          landscape: 橫
          sensor:根
          據手機的角度自動調整

          詳細說明:

          <activity …
                    android:configChanges=[one or more of: "mcc" "mnc" "locale"
                                           "touchscreen" "keyboard" "keyboardHidden"
                                           "navigation" "orientation" "fontScale"]

          </activity>
          android:configChanges
              Lists configuration changes that the activity will handle itself. When changes that are not listed occur, the activity is shut down and restarted. When a listed change occurs, the activity remains running and its onConfigurationChanged() method is called.

              Any or all of the following strings can be used to set this attribute. Values are separated by ‘|’ — for example, “locale|navigation|orientation”.
              Value         Description
              “mcc”         The IMSI mobile country code (MCC) has changed — that is, a SIM has been detected and updated the MCC.
              “mnc”         The IMSI mobile network code (MNC) has changed — that is, a SIM has been detected and updated the MNC.
              “locale”         The locale has changed — for example, the user has selected a new language that text should be displayed in.
              “touchscreen”         The touchscreen has changed. (This should never normally happen.)
              “keyboard”         The keyboard type has changed — for example, the user has plugged in an external keyboard.
              “keyboardHidden”         The keyboard accessibility has changed — for example, the user has slid the keyboard out to expose it.
              “navigation”         The navigation type has changed. (This should never normally happen.)
              “orientation”         The screen orientation has changed — that is, the user has rotated the device.
              “fontScale”         The font scaling factor has changed — that is, the user has selected a new global font size.

              All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.

          主站蜘蛛池模板: 齐河县| 大埔区| 竹北市| 洛川县| 东宁县| 宁津县| 连平县| 龙川县| 醴陵市| 河南省| 齐河县| 镶黄旗| 安国市| 衡南县| 乌拉特前旗| 白山市| 琼结县| 东丽区| 伊川县| 宁陕县| 交口县| 石首市| 永胜县| 班玛县| 洪洞县| 罗甸县| 静海县| 平顺县| 龙江县| 抚顺县| 福安市| 射阳县| 赣榆县| 绥化市| 苏尼特左旗| 元氏县| 永平县| 炎陵县| 永和县| 麻江县| 鹤岗市|