最近忙,先上示例记录一下。说明:主要都是靠网上各路大神的文章整合后出来的。
build.gradle文件
defaultConfig {
applicationId "com.my.mine"
minSdkVersion 21
targetSdkVersion 30
versionCode 101
versionName "1.0.1"
javaCompileOptions {
annotationProcessorOptions.includeCompileClasspath = true
}
flavorDimensions "" // https://blog.csdn.net/gengbaolong/article/details/101785549
}
// 多包名打包
productFlavors {
// 常用 apk
Main {
// 设置applicationId(这里很重要,两个相同applicationId的apk不同同时安装在同一台Android手机中)
applicationId defaultConfig.applicationId
versionCode defaultConfig.versionCode
versionName defaultConfig.versionName
// 自定义定义xxx字段,在AndroidManifest.xml文件中用到${xxx}
manifestPlaceholders = [
app_name : "@string/app_main",
app_theme: "@style/mainTheme",
app_icon : "@mipmap/app_logo_main"]
}
// 另一个 apk
other1 {
// 解释同app1
applicationId "com.my.other1"
versionCode 101
versionName "1.0.1_01"
manifestPlaceholders = [
app_name : "@string/app_other1",
app_theme: "@style/Other1Theme",
app_icon : "@mipmap/app_logo_other1"]
}
}
AndroidManifest.xml文件的application,的关键信息。app_theme是适配启动闪屏页
<application
android:name=".MyApplication"
android:icon="${app_icon}"
android:label="${app_name}"
android:roundIcon="${app_icon}"
android:theme="${app_theme}">
...
</application>
style.xml文件的theme;其中windowBackground就是启动闪屏页
<!-- Main application theme. -->
<style name="MainTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowBackground">@drawable/splash_background</item>
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<!--Other1的主题样式-->
<style name="HenglinAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowBackground">@drawable/splash_background_other</item>
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
splash_background_other.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 闪屏页背景 ,好处适配各种屏幕 -->
<item android:drawable="@color/white"/>
<!-- app logo -->
<item>
<bitmap
android:gravity="center"
android:src="@drawable/icon_logo"/>
</item>
</layer-list>