android:configChanges屬性

來源:互聯網
上載者:User

標籤:

對android:configChanges屬性,一般認為有以下幾點:

1、不設定Activity的android:configChanges時,切屏會重新調用各個生命週期,切橫屏時會執行一次,切豎屏時會執行兩次

2、設定Activity的android:configChanges="orientation"時,切屏還是會重新調用各個生命週期,切橫、豎屏時只會執行一次

3、設定Activity的android:configChanges="orientation|keyboardHidden"時,切屏不會重新調用各個生命週期,只會執行onConfigurationChanged方法

但是,自從Android 3.2(API 13),在設定Activity的android:configChanges="orientation|keyboardHidden"後,還是一樣 會重新調用各個生命週期的。

因為screen size也開始跟著裝置的橫豎切換而改變。所以,在AndroidManifest.xml裡設定的MiniSdkVersion和 TargetSdkVersion屬性大於等於13的情況下,

如果你想阻止程式在運行時重新載入Activity,除了設定"orientation", 你還必須設定"ScreenSize"。

解決方案:

AndroidManifest.xml中設定android:configChanges="orientation|screenSize“

 

擴張:

通過設定這個屬性可以使Activity捕捉裝置狀態變化,以下是可以被識別的內容:  
CONFIG_FONT_SCALE
CONFIG_MCC
CONFIG_MNC
CONFIG_LOCALE
CONFIG_TOUCHSCREEN
CONFIG_KEYBOARD
CONFIG_NAVIGATION
CONFIG_ORIENTATION

設定方法:將下欄欄位用“|”符號分隔開,例如:“locale|navigation|orientation

Value Description
“mcc“ The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC.移動國家號碼,由三位元字組成,每個國家都有自己獨立的MCC,可以識別手機使用者所屬國家。
“mnc“ The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen 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.全域字型大小縮放發生改變


android:configChanges屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.