Titanium - tab icons for Android do not work

So, following this concept:

http://docs.appcelerator.com/titanium/2.1/index.html#!/guide/Using_density-specific_resources_on_Android

I created a folder that was

Resources/android/images/ 

and then under this:

 high/ medium/ low/ 

and inside each of them are files with different densities (for example, about.png,

)

The problem is that when I refer to them:

 var aboutTab = Ti.UI.createTab({ icon: '/images/about.png', title: 'about', window: about }); 

OR, as others have suggested so (i.e., losing the leading slash in the "images"):

 var aboutTab = Ti.UI.createTab({ icon: 'images/about.png', title: 'about', window: about }); 

and then download the app, make sure the tabs themselves ... but no icons. Please note that if I have a plain old file located in a folder

 Resources/images/about.png 

then an icon will appear ... but not otherwise. Is there ... something that I don't see in this?

+4
source share
2 answers

Ok, so the standard answer never worked for me. I am using Titanium 2.1 here. {insert insult into the heritage of Ti developers here}

The solution to this is simple - do not use such an exalted “smart titanium density density solution” as described here:

http://docs.appcelerator.com/titanium/2.1/index.html#!/guide/Using_density-specific_resources_on_Android

Instead, use this simple, home code to fix your problems!

 var density = (Titanium.Platform.displayCaps.dpi <= 160) ? 'low' : (Titanium.Platform.displayCaps.dpi > 160 && Titanium.Platform.displayCaps.dpi < 240) ? 'medium' : 'high'; var preamble = (Ti.Platform.osname === 'iphone' || (Ti.Platform.osname === 'ipad') )? 'images':'android/images/'+density + '/'; 

Ok, so the first bit sets the density. NOTE. I don’t know the correct density readings for Ti just now, I just put it until I work out anyhoo - and the second bit uses it if the application is android.

Then, where I used to have:

 var aboutTab = Ti.UI.createTab({ icon: 'images/about.png', title: 'about', window: about }); 

i now have:

 var aboutTab = Ti.UI.createTab({ icon: preamble + '/about.png', title: 'about', window: about }); 

And here it is!

FINAL WORD: I noticed that this can behave differently depending on the version of Titanium used (2.1.3 vs 2.1.0) or the sroid file used. I had better results with 2.1.0 and 4.2 android, and that includes using the 'images' prefix (you know how the guides say to do this).

One thing I noticed is that I cannot have both high / medium / low folders and hdpi folders, I need one or the other.

Another problem that I encountered was that sometimes the code did not load the android / images / folders files. A completely bulletproof way to do this is to use the code I described, but put the density-determining folders directly in the image folder and link to them through the images / tall / etc. The content in the images is always copied to, and the code shown always works regardless of the Ti version.

Final note. Make sure your images have a case-sensitive name because it will work on a Windows emulator, but not on a real (Unix-based) device.

+1
source

enter image description here Plz read and understand with a cool mind, this works with me "More control." Paragraph.

 var aboutTab = Ti.UI.createTab({ icon: 'images/about.png', // "/" remove this and try again title: 'about', window: about }); 

plz, uninstall the old application from your device or emulator. after that "Clean", then build, I think, then it works correctly.

+1
source

Source: https://habr.com/ru/post/1432841/


All Articles