使用QT開發出的Android Apk安裝后默認的圖標是安卓的小機器人,下面介紹在QT5.12版本上修改APP名稱和圖標的方法。
1、 編譯一次項目后,在編譯目錄下找到AndroidManifest.xml
2、 試試在項目目錄下創建一個文件夾android_sources,把圖標和 AndroidManifest.xml文件放進去
3、 右鍵項目,在彈出的菜單中選擇“添加現有文件…”
4、 雙擊AndroidManifest.xml文件,在右側進行修改,在"Application icon"處設置圖標,這里有3種圖標,分別為低、中、高。
5、 最后需要在.pro文件最后加一句,表示包含Android資源文件目錄:
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android_sources
再次編譯生成,安裝后顯示:
以下是參考的內容:
First of all Create a Qt Widgets application project for Android. (if you don’t have Qt for Android installed on your computer then you can refer to this post on how to get it done!)
Next, without changing anything, just build the project. (You can run clean, qmake and then build which is what I always do to make sure things are alright.)
When you build a Qt project, a folder will be created by Qt to contain your build files. If you are using the default settings then this folder is located in the same folder where your project is located. It usually has a name similar to this: (Note that this is just an example and the folder name depends on the version and type of Qt build you are using but it has the same pattern)
build-myproject-Android_for_x86_GCC_4_9_Qt_5_5_0-Debug
如果你使用的是默認設置會在你工程的同級目錄下(注意,這里的同級目錄不是指你的pro文件所在的目錄,而是包涵pro文件的那個文件夾所在的目錄,即pro文件的上級目錄),會出現類似於“build-myproject-Android_for_x86_GCC_4_9_Qt_5_5_0-Debug”這種名字的目錄。
If you go to the build folder mentioned above, there is a folder named “android-build” inside it. Inside android-build you will find a file named AndroidManifest.xml, copy that file.
在上面的那個目錄下會有一個“android-build”,在“android-build”這個目錄下又有一個名字為“AndroidManifest.xml”的文件,現在我們復制這個文件。
Next, create a folder named “android-sources” inside your Qt project folder and copy AndroidManifest.xml there. (Note that your Qt project folder is the folder where your Qt PRO and source code CPP files etc. are located.)
下面,在工程文件所在目錄(這里是pro文件所在的目錄)下創建文件夾“android-sources”,將剛才的文件“AndroidManifest.xml”復制到這里。
Now right click your project in Qt Creator and select Add Existing Files. And select AndroidManifest.xml from the android-sources folder to add it to your project.
現在右鍵點擊你Qt Creator中的工程,選擇Add Existing Files(添加已存在的文件),將“AndroidManifest.xml”添加到工程中。如下圖:
Note that you should have this in “Other files” section of your project.
Now it’s time to actually add the icon to your android application in Qt. Double click AndroidManifest.xml to open the following window in Qt Creator. It is actually Qt’s Android Manifest editor. At the middle of the screen there are three buttons which you can press and select an icon for each one of them. They are used for setting Low DPI, Medium DPI and High DPI icons.
現在雙擊Qt中的AndroidManifest.xml文件就打開如下界面,在"Application icon"處設置圖標,這里有3種圖標,分別為低、中、高。
Finally, open your Qt project (.PRO) file and append the following line at the bottom of it.
最后在工程文件.PRO文件中加上下面這名話。
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
Now if you run your Qt Android project you should see that the icon is changed!
現在再次build,圖標就改變了。
關於程序名的更改也在AndroidManifest.xml中,就是把圖標上面的“Application name”“Activity name”改了就可以了。