"http://schemas.android.com/apk/res/android"
package="com.base.module.recorder"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system"
android:installLocation="auto|internalOnly|preferExternal"
>
manifest标签package为项目包属性, versionCode为版本整数,每次迭代则数字增加,versionName为显示给用户的公共版本号。
installLocation
属性指定是否允许(或者首选)将应用程序安装到外部存储器(SD卡)而不是内部存储器。preferExternal将应用程序首选安装到外部存储器,auto则要求系统决定。
注意:下列程序不适合安装到外置存储:对于具有Widget、Live Wallpaper和Live Folder的应用程序;提供不中断服务的应用程序;输入法引擎;设备管理器 DeviceAdminReceiver及其管理能力将被禁用。
uses-sdk
该节点用于定义要想正确运行应用程序,设备上必须具有的最低和最高SDK版本,以及为应用程序设计的目标SDK,分别通过minSDKVersion、maxSDKVersion和targetSDKVersion属性设置。
通常在开发中将targetSDKVersion指定为最高SDK版本。
通常没有必要指定最高SDK版本。
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="27" />
uses-configuration
可以指定应用程序支持的每个输入机制的组合,一般不需要包含,但是对于特殊输入控制的游戏很有用。
uses-feature
指定应用程序需要的每个硬件功能。这样可以避免将应用程序安装到不包含必要的硬件功能(如NFC硬件)的设备。
<uses-feature android:name="android.hardware.nfc" android:required="false"/>
required属性可以覆盖暗含对硬件的需求。
<uses-feature android:glEsVersion="0x00010001"/>
指定OpenGL的最低版本,高16位代表主版本号,低16位代表次版本号。
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:largestWidthLimitDp="720"
android:compatibleWidthLimitDp="600"
android:requiresSmallestWidthDp="480"
android:anyDensity="true"
android:smallScreens="false"
android:xlargeScreens="false"
android:resizeable="true">
supports-gl-texture
用于声明应用程序能够提供的以一种特定的GL纹理压缩格式压缩的纹理资源。
uses-permission 作为安全模型的一部分,声明了应用程序需要。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<permission android:name="com.test.MYTEST"
android:protectionLevel="dangerous"
android:description="xx"
android:label="xx"/>
访问权限的级别包括(normal | dangerous | signature | signatureOrSystem)
<instrumentation
android:label="xx"
android:name="xx"
android:targetPackage="xx"/>
"com.base.module.recorder.RecorderApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true">
activity
每个Activity都要求一个activity标签,允许使用intent-filter标签定义用于启动该Activity的Intent。
Service
同Activity。
Provider 指定应用程序中每个Content Provider。用于管理数据库访问和共享。
<uses-library android:name="xx"
android:required="false"/>
ADT插件包含了一个Manifest Editor来管理Manifest,这样,就不用直接对底层的xml进行操作,直接通过gui可以添加删除相关节点。
常用资源类型如下
<string name="turn_off_auto_record">Turn off auto recordingstring>
<plurals name="androidPlurals">
<item quantity="one">One androiditem>
<item quantity="other">%d androiditem>
plurals>
<color name="app_bg">#ff0000ffcolor>
<dimen name="def_border">5pxdimen>
<string-array name="string_array">
<item>1item>
<item>2item>
<item>3item>
string-array>
<array name="integer_array">
<item>3item>
<item>2item>
<item>1item>
array>
Android支持简单的文本样式,所以可以使用HTML标签 来让文本字符串变为粗体、斜体及下划线。
<string name="test_string">Turn off auto recordingStop.string>
当为String.format方法输入参数时可以使用资源字符串。然而String.format不支持上面描述的文本样式。为了对一个格式化字符串使用样式,需要在创建资源时候转义为HTML标签,如下所示:
<string name="test_string">Turn off auto recording<b>Stop</b>.%1$sstring>
在代码内,可以使用Html.fromHtml方法把这些字符串转换回样式字符序列:
String reString = getString(R.string.xx);
String fString = String.format(reString, "xx");
CharSequence styledString = Html.fromHtml(fString);
通过plurals为字符串定义复数形式。
int unitCount = 2;
String unitString = getResources().getQuantityString(R.plurals.androidPlurals, unitCount, unitCount);
对象计数传入两次,一次用于返回正确的复数字符串,一次作为输出参数让句子变得完整。
<color name="app_bg">#ff0000ff
尺寸
px(像素)
in(物理英寸)
pt(物理点)
dp(非密度制约的像素)
sp(缩放比例无关的像素)
<dimen name="standard_boarder">5dpdimen>
<dimen name="large_font_size">16spdimen>
样式可以继承,从而使得创建简单的变体形式变得十分简单。
包括位图和.9 png图像,也包含复杂复合Drawable,比如可以在xml中定义LevelListDrawable和StateListDrawable.
五种布局
LinearLayout
RelativeLayout
FrameLayout
TableLayout
AbsoluteLayout
属性动画 可以实现补间动画的功能
补间动画 旋转、缩放、平移、淡入淡出
帧动画 如视频帧播放
android:layout_height="@dimen/list_item_hight"
android:background="@drawable/info_background"
android:layout_marginTop="@android:dimen/app_icon_size"
android:textColor="?android:textColor"
这种方式可以定义随当前主题改变而改变的样式,而不必对每个资源更改。
<activity
android:name="com.base.module.recorder.RecordActivity"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:configChanges="orientation|keyboard|mnc|locale">
activity>
在Activity中复写onConfigChanged中监听这种变化,从而进行合适的处理。
Android应用程序并不能完全控制它们的生命周期,需要监听程序状态做相应改变。
在Manifest中使用Process标签可以让Activity运行在单独进程中,也可以使不同进程运行在同一个process中。
系统回收资源时,进程被终止的顺序是由它们的优先级决定的,一个应用程序的优先级等同于它组件中最高优先级。
当两个进程优先级相同,谁在低的优先级上运行的时间长,谁就先被终止。