通过设置ConfigChanges这个属性可以捕捉设备状态变化。

例转屏时,保存所做操作继续进行。具体设置如下:
1 在相关的AndroidMainfest.xml中
<activity
添加android:configChanges="orientation"
2 在相关的.java文件中添加方法

  @Override    public void onConfigurationChanged(Configuration newConfig) {            super.onConfigurationChanged(newConfig);            if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {        //landscape表示横向            } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {       //portrait表示纵向            }    }  

在android中每次屏幕的切换会重启Activity。加上configChanges=“keyboardHidden”属性,就不会重启activity,而是去调用onConfigurationChanged方法。

ConfigChanges设置方法:将下列字段用“|”分隔开,例:“orientation|keyboardHidden"

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.content.res.configuration

更多相关文章

  1. android异常 Permission denied (maybe missing INTERNET permis
  2. Android(安卓)中发送邮件
  3. IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android(安卓)apk
  4. android 设置控件的字体
  5. android学习笔记之一常用控件
  6. Android修改系统语言
  7. Android中visibility属性
  8. Android中Gallery 点击图片放大
  9. Android开发小技巧系列(六)

随机推荐

  1. PHP代码如何转 .NET?
  2. C语言中数组元素的下标下限是什么
  3. c语言如何实现做界面
  4. c语言return的用法是什么?
  5. “->” 在 C 语言什么意思?
  6. C 语言结构体详解
  7. c语言break和continue用法
  8. C语言--x和x--的区别
  9. c语言中fun用法详解
  10. c++中string类的常用方法有哪些