技术开发 频道

AndroidManifest.xml文件剖析(一)

  【IT168 技术】很多网友对于Android全局配置文件AndroidManifest.xml不是很熟悉,今天我们就一起看下它完整的结构以及每个节点的作用。在我们日常的开发中都少不了下面的配置,每创建一个Activity、Service都离不开这个全局配置文件,深入的了解可以简化程序代码以及提高程序的维护性。

  在最外层包含了包名如 package="cn.android123.demo" 、软件的版本号 android:versionCode="1" 以及 android:versionName="1.0" ,里面一层的application分支中将可能包含Android程序的四种对象 Activity、Service、Content Provider以及Receiver。我们每添加上面四个类型中的任一新对象都需要在androidmanifest.xml文件中添加相应节点。

  其中Activity的属性常用的可能为android:name和android:label但我们需要了解所有的属性以帮助解决复杂的问题,完整的如下:

          android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState
=["true" | "false"]
          android:clearTaskOnLaunch
=["true"" | "false"]
          android:configChanges=[one or more of: "mcc" "mnc" "locale"
                                
"touchscreen" "keyboard" "keyboardHidden"
                                
"navigation" "orientation" "fontScale"]
          android:enabled
=["true" | "false"]
          android:excludeFromRecents
=["true" | "false"]
          android:exported
=["true" | "false"]
          android:finishOnTaskLaunch
=["true" | "false"]
          android:icon
="drawable resource"
          android:label
="string resource"
          android:launchMode
=["multiple" | "singleTop" |
                              
"singleTask" | "singleInstance"]
          android:multiprocess
=["true" | "false"]
          android:name
="string"
          android:noHistory
=["true" | "false"]  
          android:permission
="string"
          android:process
="string"
          android:screenOrientation
=["unspecified" | "user" | "behind" |
                                    
"landscape" | "portrait" |
                                    
"sensor" | "nonsensor"]
          android:stateNotNeeded
=["true" | "false"]
          android:taskAffinity
="string"
          android:theme
="resource or theme"
          android:windowSoftInputMode
=[one or more of: "stateUnspecified"
                                      
"stateUnchanged" "stateHidden"
                                      
"stateAlwaysHidden" "stateVisible"
                                      
"stateAlwaysVisible" "adjustUnspecified"
                                      
"adjustResize" "adjustPan"] >  
0