簡體   English   中英

如何更改 flutter 的桌面 windows 應用程序圖標?

[英]how to change desktop windows application icon for flutter?

我使用桌面 flutter 並搜索了一種方法,但我找不到任何關於該 sp 的文章我想知道如何更改 windows 桌面以及 mac 和 ZE206A54E97690CCE50CC872DD70EE8 的啟動器應用程序圖標。

要更改圖標,您只需要替換項​​目中的圖標文件:

  • Windows:windows/runner/resources/app_icon.ico
  • macOS:macos/Runner/Assets.xcassets/AppIcon.appiconset

Linux 還沒有在模板中設置圖標; 您可以關注此問題以獲取更新。

要更改 Windows 中的圖標,您必須將圖標文件保留在此位置:

窗口/跑步者/資源/

然后進入 windows/runner/resources/Runner.rc 文件並搜索單詞app_icon 您將到達這里:

IDI_APP_ICON            ICON                    "resources\\app_icon.ico"

app_icon替換為您的圖標文件名。 然后運行命令

flutter build windows
flutter run --release -d windows

這是我從flutter doctor那里得到的設置

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19043.1110], locale en-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.3)
[✓] Android Studio (version 4.1.0)
[✓] Android Studio
[✓] Connected device (3 available)

• No issues found!

最初只是替換圖標並運行它不起作用

flutter build windows

也沒有

flutter clean
flutter build windows

我發現在運行模式下,GUI 上的圖標會更新,但不幸的是 EXE 本身不會更新。

flutter run --release -d windows

對於 Linux

最好最簡單的方法是使用gtk_window_set_icon_from_file function

編輯 Linux 文件夾linux/my_application.cc中的my_application.cc文件

  • 行前gtk_widget_show(GTK_WIDGET(window));
  • 添加新行gtk_window_set_icon_from_file(GTK_WINDOW(window),"assets/icon.ico",NULL);
  • 圖標推薦 48x48 像素

我有最好的方法,為您的 Windows、Android 等使用Flutter 啟動器圖標

  1. 編輯您的pubspec.yaml文件:

dev_dependencies:flutter_launcher_icons:“^0.10.0”

 flutter_icons: android: "launcher_icon" ios: true image_path: "assets/icon/icon.png" min_sdk_android: 21 # android min sdk min:16, default 21 web: generate: true image_path: "path/to/image.png" background_color: "#hexcode" theme_color: "#hexcode" windows: generate: true image_path: "path/to/image.png" icon_size: 48 # min:48, max:256, default: 48
  1. Go 到終端,運行:
 flutter pub get flutter pub run flutter_launcher_icons:main

注意:您的圖標名稱是小寫的,不要使用大寫。

暫無
暫無

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

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