android:configChanges屬性

android:configChanges屬性有以下幾個常用知識點:

1、不設置Activity的android:configChanges時,切屏會重新調用各個生命週期,切橫屏時會執行一次,切豎屏時會執行兩次(注意橫豎屏是不一樣的,橫一豎二)

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

3、設置Activity的android:configChanges="orientation|keyboardHidden"時,切屏不會重新調用各個生命週期,只會執行onConfigurationChanged方法(這裏不知道爲什麼keyboardHidden屬性會影響到切屏)

4、這裏是重點!!!但是,自從Android 3.2(API 13),在設置Activity的android:configChanges="orientation|keyboardHidden"後,還是一樣會重新調用各個生命週期的。因爲screen size也開始跟着設備的橫豎切換而改變。所以,在AndroidManifest.xml裏設置的MiniSdkVersion和 TargetSdkVersion屬性大於等於13的情況下,如果你想阻止程序在運行時重新加載Activity,除了設置"orientation"、"keyboardHidden",你還必須設置"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.全局字體大小縮放發生改變



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章