本文主要是介绍11.8学习内容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://blog.csdn.net/xcookies/article/details/40926503
今天有幸去哥们的大公司做了半天的临时工,一个偶现的Bug折腾了他好久,好不容易今天抓到了异常Log日志,大致的意思就是android.view.windowleaked——窗体泄漏。我在网上查了资料:
Android的每一个Activity都有个WindowManager窗体管理器,构建在某个Activity之上的对话框、PopupWindow也有相应的WindowManager窗体管理器。因为Dialog、PopupWindown不能脱离Activity而单独存在着,所以当承载某个Dialog或者某个PopupWindow正在显示的Activity被finish()后,而Dialog(或PopupWindow)没有正常退出的话,就会抛Window Leaked错误了,因为这个Dialog(或PopupWindow)的WindowManager已经没有谁可以附属了,所以它的窗体管理器就泄漏了。
根据此信息分析出,在进入新的Activity时突然转屏(哥们开发的sdk支持横竖屏切换),因为在AndroidManifest.xml中没有配置android:configChanges属性,此时Activity会重新调用onCreate方法,即会重新调用整个生命周期,而此时的Dialog已经显示并没有dismiss,所以造成了窗体泄漏。解决的方法就变得如此简单,在AndroidManifest.xml中配置android:configChanges属性,这样当我们横竖屏切换的时候会调用Activity的onConfigurationChanged方法,不会重新调用整个生命周期了。我们最后配置了android:configChanges="screenSize|orientation|keyboardHidden|navigation"。
既然谈到了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"后,还是一样会重新调用各个生命周期的。因为screensize也开始跟着设备的横竖切换而改变。所以在AndroidManifest.xml里设置的MiniSdkVersion和 TargetSdkVersion属性大于等于13的情况下,如果你想阻止程序在运行时重新加载Activity,除了设置"orientation", 你还必须设置" screenSize"。
——以上信息从网上看到,觉得很有用,但自己并没有验证过,不过相信也是LZ验证过发出的,应该会很有用的。
附上android:configChanges属性解释:
VALUE | DESCRIPTION |
"mcc" | 国际移动用户识别码所属国家代号是改变了----- sim被侦测到了,去更新mcc mcc是移动用户所属国家代号 |
"mnc" | 国际移动用户识别码的移动网号码是改变了------ sim被侦测到了,去更新mnc MNC是移动网号码,最多由两位数字组成,用于识别移动用户所归属的移动通信网 |
"locale" | 地址改变了-----用户选择了一个新的语言会显示出来 |
"touchscreen" | 触摸屏是改变了------通常是不会发生的 |
"keyboard" | 键盘发生了改变----例如用户用了外部的键盘 |
"keyboardHidden" | 键盘的可用性发生了改变 |
"navigation" | 导航发生了变化-----通常也不会发生 |
"screenLayout" | 屏幕的显示发生了变化------不同的显示被激活 |
"fontScale" | 字体比例发生了变化----选择了不同的全局字体 |
"uiMode" | 用户的模式发生了变化 |
"orientation" | 屏幕方向改变了 |
"screenSize" | 屏幕大小改变了 |
"smallestScreenSize" | 屏幕的物理大小改变了,如:连接到一个外部的屏幕上 |
今天收获不小,见识了大公司的霸气,也加深了android:configChanges属性的了解。
http://blog.csdn.net/minimicall/article/details/40889241
摘要 Android平台定义的主题样式: android:theme="@android:style/Theme.Dialog" // 将一个Activity显示为对话框模式android:theme="@android:style/Theme.NoTitleBar" // 不显示应用程序标题栏android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //
Android平台定义的主题样式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | android:theme= "@android:style/Theme.Dialog" // 将一个Activity显示为对话框模式 android:theme= "@android:style/Theme.NoTitleBar" // 不显示应用程序标题栏 android:theme= "@android:style/Theme.NoTitleBar.Fullscreen" // 不显示应用程序标题栏,并全屏 android:theme= "@android:style/Theme.Light" // 背景为白色 android:theme= "@android:style/Theme.Light.NoTitleBar" // 白色背景并无标题栏 android:theme= "@android:style/Theme.Light.NoTitleBar.Fullscreen" // 白色背景,无标题栏,全屏 android:theme= "@android:style/Theme.Black" // 背景黑色 android:theme= "@android:style/Theme.Black.NoTitleBar" // 黑色背景并无标题栏 android:theme= "@android:style/Theme.Black.NoTitleBar.Fullscreen" // 黑色背景,无标题栏,全屏 android:theme= "@android:style/Theme.Wallpaper" // 用系统桌面为应用程序背景 android:theme= "@android:style/Theme.Wallpaper.NoTitleBar" // 用系统桌面为应用程序背景,且无标题栏 android:theme= "@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" // 用系统桌面为应用程序背景,无标题栏,全屏 android:theme= "@android:style/Translucent" // 半透明效果 android:theme= "@android:style/Theme.Translucent.NoTitleBar" // 半透明并无标题栏 android:theme= "@android:style/Theme.Translucent.NoTitleBar.Fullscreen" // 半透明效果,无标题栏,全屏 |
Android平台定义了三种字体大小:
1 2 3 | "?android:attr/textAppearanceLarge" "?android:attr/textAppearanceMedium" "?android:attr/textAppearanceSmall" |
Android字体颜色:
1 2 3 4 5 | android:textColor= "?android:attr/textColorPrimary" android:textColor= "?android:attr/textColorSecondary" android:textColor= "?android:attr/textColorTertiary" android:textColor= "?android:attr/textColorPrimaryInverse" android:textColor= "?android:attr/textColorSecondaryInverse" |
Android的ProgressBar样式:
1 2 3 4 | style= "?android:attr/progressBarStyleHorizontal" style= "?android:attr/progressBarStyleLarge" style= "?android:attr/progressBarStyleSmall" style= "?android:attr/progressBarStyleSmallTitle" |
分隔符
横向:
1 2 3 | <View android:layout_width= "fill_parent" android:layout_height= "1dip" android:background= "?android:attr/listDivider" /> |
纵向:
1 2 3 | <View android:layout_width= "1dip" android:layout_height= "fill_parent" android:background= "?android:attr/listDivider" /> |
CheckBox样式:
style="?android:attr/starStyle"
类似标题栏效果的TextView
style="?android:attr/listSeparatorTextViewStyle"
其它有用的样式:
1 2 3 4 5 6 | android:layout_height= "?android:attr/listPreferredItemHeight" android:paddingRight= "?android:attr/scrollbarSize" style= "?android:attr/windowTitleBackgroundStyle" style= "?android:attr/windowTitleStyle" android:layout_height= "?android:attr/windowTitleSize" android:background= "?android:attr/windowBackground" |
修改Activity的标题栏样式
如在styles.xml中增加:
1 2 3 4 5 6 7 8 9 | <resources> <style name= "AutoWindowTitleBackground" > <item name= "android:background" > #778899</item> </style> <style name= "autoWindowTitlebar" parent= "android:Theme" > <item name= "android:windowTitleSize" >32dp</item> <item name= "android:windowTitleBackgroundStyle" >@style/AutoWindowTitleBackground</item> </style> </resources> |
接着再修改AndroidManifest.xml文件,找到要自定义标题栏的Activity,添加上android:theme值,比如:
1 2 | <activity android:name= ".MainActivity" android:theme= "@style/autoWindowTitlebar" > |
去掉所有Activity界面的标题栏
修改AndroidManifest.xml
在application 标签中添加:
1 | android:theme=”@android:style/Theme.NoTitleBar” |
这篇关于11.8学习内容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!