A few weeks back, I showed how you can tweak the name of your Titanium iOS app. By using the internationalization (i18n) feature of Titanium, I was able to configure an app named TestApp to show on the home screen as “My Cool App”.
We can do the same thing for a Titanium Android app, however the process is a little different. To modify the app’s name, we’ll have to use the native Android strings files instead of Titanium’s i18n files. We’ll also need to tweak the manifest, which means a bit of XML tweaking in the tiapp.xml file.
Let me lay out the steps we’ll take first, then I’ll go through them in more detail:
- Create the project_root/platform/android/res/values-LANG/strings.xml file.
- Build your app for Android once to create the stock AndroidManifest.xml file.
- Copy values from the stock AndroidManifest.xml to tiapp.xml.
- Edit the tiapp.xml to enable the native strings.
Step 1: Create the strings file
Start by creating the folder structure: in your project’s directory, create the platform/android/res folders and then inside, create a folder denoting the target language. For example, for US English, the folder would be values-en. Inside that folder, we’ll need to create the native strings file. You can use the app.xml file you created for iOS but you’ll need to rename it to strings.xml. If you haven’t created the iOS version, see the past blog post for the file’s XML structure.
Step 2: Build your app
We’ll need entries from the generated AndroidManifest.xml file. To get those, you’ll need to build your app once. There’s no sense in installing the app yet. At the command-line, from within your project’s folder, issue this command:
ti build -p android -b
That will generate the /build/android/AndroidManifest.xml file. Open that file in a text editor (like Studio).
Step 3. Update the tiapp.xml
Open tiapp.xml in Studio and switch to the XML view. Locate the <android>
tag and remove the “/” from the end of it. Add a closing </android>
tag.
Next, from the generated AndroidManifest.xml file, copy the entire <manifest>...</manifest>
block of tags. Paste them into the tiapp.xml between the opening and closing <android>
tags.
Step 4. Enable the native string
Finally, we need to tweak the code you just pasted into the tiapp.xml. You need to replace the hard-coded app name with @string/appname, which is a “variable reference” to the string’s value in your language file. Most likely, you’ll find multiple references to your app’s name throughout the activities of your app. Make sure you change all the references.
Finally, you need to build and install your app. You can do so from Studio. Or, if you’re using the speedy new Genymotion Android emulator like me, issue these two commands:
ti build -p android -b adb install -r build/android/bin/app.apk