android自適應滑動鍵盤產生的螢幕尺寸變化

weixin_34344677發表於2009-02-17

預設情況下,滑動鍵盤會重新啟動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.

相關文章