Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): change app icons at runtime #14162

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Dec 22, 2024

Summary

Android can change activity icons during runtime to predefined <activity-alias> nodes. We can add those into tiapp.xml.

Bildschirmaufnahme_20241222_192541.webm

This PR will add a method to switch from one to another alias and makes a change to the build script to not add the default LAUNCHER intent if there are alias nodes.

Test

  • Create an app with the name test and add this to the <application> node:
<activity-alias android:enabled="true" android:name=".default" android:targetActivity=".TestActivity" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity-alias>
<activity-alias android:icon="@mipmap/ic_launcher" android:name=".red" android:enabled="false" android:targetActivity=".TestActivity" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity-alias>
  • use icon.kitchen and download the default icon.
  • put the file res content into app/platform/android/
  • run this app code
var win = Ti.UI.createWindow({
	layout: "vertical"
});

var btn1 = Ti.UI.createButton({
	title: "switch to red"
});
var btn2 = Ti.UI.createButton({
	title: "switch to default"
});
var btn3 = Ti.UI.createButton({
	title: "switch broken"
});

btn1.addEventListener("click", function() {
	Ti.App.Android.changeIcon({
		from: "default",
		to: "red"
	});
});
btn2.addEventListener("click", function() {
	Ti.App.Android.changeIcon({
		from: "red",
		to: "default"
	});
});
btn3.addEventListener("click", function() {
	Ti.App.Android.changeIcon({
		from: "default"
	});
});

win.add([btn1, btn2, btn3]);
win.open();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant