簡體   English   中英

Android如何在產品口味中使用不同的應用程序圖標和應用程序名稱

[英]Android how to use different app icon and app name in product flavors

我使用 twodiffrenert 產品味道

  1. 付費版
  2. 免費版

我需要使用不同的應用程序圖標和應用程序名稱請最好的建議

您可以使用構建變體來實現您的目的:

構建.gradle

android{

    defaultConfig {
        applicationId "com.example.test"
      //...
    }
    flavorDimensions "mode"
    productFlavors {

        paid {
            applicationIdSuffix ".paid"
            flavorDimensions "mode"
        }

        free {
            applicationIdSuffix ".free"
            flavorDimensions "mode"
        }
    }
}

AndroidManifest.xml:

<manifest 

    ...
        <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    ...

    </application>

</manifest>

這樣,您應該在您的項目中創建如下兩種 sourceSet。 例如,您可以在 string.xml 中創建應用程序名稱字符串,並在自定義免費源集的 mipmap 中添加新的應用程序圖標

在此處輸入圖像描述

除了如下圖創建兩個 sourceSet 之外,您還可以使用 manifestPlaceholders 並且不需要創建任何其他 sourceSet:

構建.gradle

android{
    defaultConfig {
        applicationId "com.example.test"
      //...
    }
    flavorDimensions "mode"
    productFlavors {

        paid {
            applicationIdSuffix ".paid"
            flavorDimensions "mode"
            manifestPlaceholders = [
                 "app_icon": "@mipmap/icon_paid",
                 "app_name": "paid~~~",
            ]
        }

        free {
            applicationIdSuffix ".free"
            flavorDimensions "mode"
            manifestPlaceholders = [
                 "app_icon": "@mipmap/icon_free",
                 "app_name": "free~~~",
            ]
        }
    }
}

AndroidManifest.xml

<manifest 

    ...
        <application
        android:allowBackup="true"
        android:icon="${app_icon}"
        android:label="${app_name}"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    ...

    </application>

</manifest>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM