generated from dellevin/template
自定义图标
This commit is contained in:
@@ -17,11 +17,38 @@
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
</activity>
|
||||
|
||||
<!-- 图标1: 默认图标 -->
|
||||
<activity-alias
|
||||
android:name=".MainActivityIcon1"
|
||||
android:targetActivity=".MainActivity"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
android:label="MookNote">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</activity-alias>
|
||||
|
||||
<!-- 图标2: 风格二 -->
|
||||
<activity-alias
|
||||
android:name=".MainActivityIcon2"
|
||||
android:targetActivity=".MainActivity"
|
||||
android:enabled="false"
|
||||
android:exported="true"
|
||||
android:icon="@mipmap/ic_launcher2"
|
||||
android:roundIcon="@mipmap/ic_launcher2"
|
||||
android:label="MookNote">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
|
||||
@@ -1,5 +1,62 @@
|
||||
package top.iletter.mooknote
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.pm.PackageManager
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
class MainActivity : FlutterActivity() {
|
||||
|
||||
private val CHANNEL = "top.iletter.mooknote/icon"
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"switchIcon" -> {
|
||||
val iconName = call.argument<String>("iconName")
|
||||
if (iconName != null) {
|
||||
switchLauncherIcon(iconName)
|
||||
result.success(true)
|
||||
} else {
|
||||
result.error("INVALID_ARGUMENT", "iconName is required", null)
|
||||
}
|
||||
}
|
||||
"getCurrentIcon" -> {
|
||||
result.success(getCurrentIcon())
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun switchLauncherIcon(iconName: String) {
|
||||
val pm = packageManager
|
||||
val icon1 = ComponentName(this, "${packageName}.MainActivityIcon1")
|
||||
val icon2 = ComponentName(this, "${packageName}.MainActivityIcon2")
|
||||
|
||||
when (iconName) {
|
||||
"app_icon2" -> {
|
||||
pm.setComponentEnabledSetting(icon1, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
||||
pm.setComponentEnabledSetting(icon2, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
||||
}
|
||||
else -> {
|
||||
pm.setComponentEnabledSetting(icon2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
||||
pm.setComponentEnabledSetting(icon1, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCurrentIcon(): String {
|
||||
val pm = packageManager
|
||||
val icon1 = ComponentName(this, "${packageName}.MainActivityIcon1")
|
||||
val icon2 = ComponentName(this, "${packageName}.MainActivityIcon2")
|
||||
|
||||
return when {
|
||||
pm.getComponentEnabledSetting(icon2) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> "app_icon2"
|
||||
else -> "app_icon"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher2.png
Normal file
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher2.png
Normal file
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher2.png
Normal file
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher2.png
Normal file
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher2.png
Normal file
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Reference in New Issue
Block a user