简体   繁体   English

如何以编程方式更改 android 中的应用程序托盘图标?

[英]How to change the app tray icon in android programmatically?

I had changed the app icon and app name dynamically.我已经动态更改了应用程序图标和应用程序名称。 But the app launching icon is not changed after the app icon and app name change.但是应用程序图标和应用程序名称更改后,应用程序启动图标不会更改。 Please guide.请指导。

I switched the app icon and name using activity alias concept.我使用活动别名概念切换了应用程序图标和名称。 See image for issue: issue image查看问题图片:问题图片

Code:代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.batpoc">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases, you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="bat poc"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"              
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
          <intent-filter>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <activity-alias
            android:label="bat poc"
            android:name=".MainActivityDefault"
            android:enabled="true"
            android:icon="@mipmap/ic_launcher"            
            android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

      <activity-alias
            android:name=".MainActivityOneLaunch"
            android:enabled="false"
            android:logo="@mipmap/th"
            android:label="One Launch"
            android:icon="@mipmap/th"            
            android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

</application>

I think that's the phone's issue.我觉得是手机的问题。 The phone might have stored some cache files of the app and hence the icon is not changed.手机可能已经存储了应用程序的一些缓存文件,因此图标没有更改。 Just clear the data of the app, then uninstall it, then reboot your phone and then build the app again.只需清除应用程序的数据,然后将其卸载,然后重新启动手机,然后再次构建应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM