安卓切换语⾔后activity重启解决⽅法以及
configChanges属性
卡了蛮久,试了很多⽅法,最后发现只要在l中配置configChanges属性就OK
android:configChanges="locale|layoutDirection"
只要加上这条属性,切换语⾔时activity就不会重启
有的时候解决问题的办法很简单,就看你愿不愿意花时间去琢磨了
最后总结⼀下configChanges的各种属性:
android:configChanges=["mcc", "mnc", "locale","touchscreen", "keyboard", "keyboardHidden","navigation", "screenLayout", "fontScale", "uiMode","orientation", "screenSize", "smallestScreenSize"]
mcc:The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.IMSI(国际移动⽤户识别码)发⽣改变,检测到SIM卡,或者更新MCC
mnc:The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.
IMSI⽹络发⽣改变,检测到SIM卡,或者更新MCC
其中mcc和mnc理论上不可能发⽣变化
locale:The locale has changed — the user has selected a new language that text should be displayed in.
语⾔发⽣改变,⽤户选择了⼀个新的语⾔,⽂字应该重新显⽰
rotate属性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 revealed the hardware keyboard.
键盘发⽣改变,例如,⽤户使⽤了硬件键盘
navigation:The navigation type (trackball/dpad) has changed. (This should never normally happen.)
导航发⽣改变,(这通常不应该发⽣)举例:连接蓝⽛键盘,连接后确实导致了navigation的类型发⽣变化。因为连接蓝⽛键盘后,我可以使⽤⽅向键来navigate了screenLayout:The screen layout has changed — this might be caused by a different display being activated.
屏幕的布局发⽣改变,这可能导致激活不同的显⽰
fontScale:The font scaling factor has changed — the user has selected a new global font size.
全局字体⼤⼩缩放发⽣改变
orientation:The screen orientation has changed — that is, the user has rotated the device.设备旋转,横向显⽰和竖向显⽰模式切换。
screenSize: 屏幕⼤⼩改变了
smallestScreenSize: 屏幕的物理⼤⼩改变了,如:连接到⼀个外部的屏幕上
4.2增加了⼀个layoutDirection属性,当改变语⾔设置后,该属性也会成newConfig中的⼀个mask位。所以ActivityManagerService(实际在ActivityStack)在决定是否重启Activity的时候总是判断为重启。
需要在android:configChanges 中同时添加locale和layoutDirection。
在不退出应⽤的情况下切换到Settings⾥切换语⾔,发现该Activity还是重启了。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。