Activity中ConfigChanges屬性的用法
通過設置這個屬性可以使Activity捕捉設備狀態變化,以下是可以被識別的內容:
CONFIG_FONT_SCALE
CONFIG_MCC
CONFIG_MNC
CONFIG_LOCALE
CONFIG_TOUCHSCREEN
CONFIG_KEYBOARD
CONFIG_NAVIGATION
CONFIG_ORIENTATION
設置方法:將下列字段用“|”符號分隔開,例如:“locale|navigation|orientation
”
Value | Description | </tr>|||||||||||||||||||||||||||
“mcc“ | The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC.移動國家號碼,由三位數字組成,每個國家都有自己獨立的MCC,可以識別手機用戶所屬國家。 | </tr>|||||||||||||||||||||||||||
“mnc“ | The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen detected and updated the MNC.移動網號,在一個國家或者地區中,用于區分手機用戶的服務商。 | </tr>|||||||||||||||||||||||||||
“locale“ | The locale has changed — for example, the user has selected a new language that text should be displayed in.用戶所在地區發生變化。 | </tr>|||||||||||||||||||||||||||
“touchscreen“ | The touchscreen has changed. (This should never normally happen.) | </tr>|||||||||||||||||||||||||||
“keyboard“ | The keyboard type has changed — for example, the user has plugged in an external keyboard.鍵盤模式發生變化,例如:用戶接入外部鍵盤輸入。 | </tr>|||||||||||||||||||||||||||
“keyboardHidden“ | The keyboard accessibility has changed — for example, the user has slid the keyboard out to expose it.用戶打開手機硬件鍵盤 | </tr>|||||||||||||||||||||||||||
“navigation“ | The navigation type has changed. (This should never normally happen.) | </tr>|||||||||||||||||||||||||||
“orientation“ | The screen orientation has changed — that is, the user has rotated the device.設備旋轉,橫向顯示和豎向顯示模式切換。 | </tr>|||||||||||||||||||||||||||
“fontScale“ | The font scaling factor has changed — that is, the user has selected a new global font size.全局字體大小縮放發生改變 | </tr> </tbody> </table> 通過一個例子介紹這個屬性的用法: 首先需要修改項目的manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidres.ConfigChangedTesting" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ConfigChangedTesting" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
</tr>
</tbody>
</table>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/pick" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Pick" /> <Button android:id="@+id/view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="View" /> </LinearLayout> |
</tr>
</tbody>
</table>