question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow adding drawable to icon externally

See original GitHub issue

I have a use case that does not allow me to add icons as specified in the custom icon packs wiki. The drawable I am trying to add to the icon pack has two paths and cannot possibly be added using the custom icons XML since the icon element can only allow one path attribute.

I am thinking of going through a route that adds such icons by manually creating Icon instances and adding them to the IconPack (hopefully that approach does not present a problem) but the icon drawable property is set as internal. Is there a reason the drawable property has an internal modifier?

Thanks for the awesome lib.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
maltaisncommented, Feb 12, 2020

The IconPack.drawable property is internal because I supposed only the IconDrawableLoader would have load icons.

Even if you were able to set them manually, I’m not sure if the icon dialog will support your icons, because they will get tinted. You would need to have only monochromatic opaque icons, which can always be represented with a single path anyway. (you can do path union with inkscape or similar tools if that’s your case)

I can make the property public and add an option to disable tinting if it’s problematic, but you’ll probably need another way of indicating selection. Also, depending on the number of icons you have, creating them programmatically may not be the most elegant solution.

Of course, it would also be possible to extend the library functionality to allow defining icons with multiple paths of different colors like this:

<icon id="0" tags="android,studio,ide,editor,dev" width="256" height="256">
    <path data="M128.09 5.02a110.08 110.08 0 0 0-110 110h220a109.89 109.89 0 0 0-110-110z" color="#7cb342"/>
    <path data="M128.09 115.02h-110a110.08 110.08 0 0 0 110 110 110.08 110.08 0 0 0 110-110z" color="#8bc34a"/>
    <path data="M207.4 115.2v-.18h-5.1l-61.43-61.43h-25.48v20.6h-6.5a11.57 11.57 0 0 0-11.53 11.53v26.09h.11c-.11.9.5 2 1.7 3.32.12.08.12.08.12.2l3.96 4-46.11 79.91c5.33 4.5 11.04 8.4 17 11.8a109.81 109.81 0 0 0 108.04 0 110.04 110.04 0 0 0 51.52-64.65c.38-1.28.68-2.57 1.1-3.78z" color="#30000000"/>
    <path data="M216.28 230.24a6.27 6.27 0 0 0-.9-2.8l-31.99-55.57-10.58-18.48-19.85-34.21-15.08 15.12 18.6 32.28 10.2 17.73 30.92 53.37a5.6 5.6 0 0 0 1.97 2.12l15.42 10.5c.6.39 1.29.39 1.9.08.6-.37.9-.98.9-1.7z" color="#e1e1e1"/>
    <path data="M186.98 115.02a58.9 58.9 0 0 1-30.5 51.6 58.4 58.4 0 0 1-56.7 0l18.6-32.28-15.13-15.12-62.48 108.22c-.5.9-.8 1.78-.9 2.8l-1.4 18.6c-.12.71.3 1.28.9 1.7.6.37 1.29.3 1.9-.12l15.41-10.4a7.87 7.87 0 0 0 1.97-2.07l30.92-53.53a78.74 78.74 0 0 0 77.23 0 76.65 76.65 0 0 0 16.6-12.4 79.3 79.3 0 0 0 24.07-56.89z" color="#f1f1f1"/>
    <path data="M147.3 74.12h-6.43v-20.6h-25.48v20.6h-6.5a11.57 11.57 0 0 0-11.53 11.5v26.07h.11c-.11 1.02.5 2.12 1.82 3.4l23.05 23.14a8.3 8.3 0 0 0 5.75 2.38v-.07l.07.07c2.12 0 4.2-.75 5.71-2.38l23.1-23.1c1.32-1.32 1.81-2.53 1.81-3.4h.12V85.7a11.68 11.68 0 0 0-11.6-11.6zm-19.14 40.9h-.07a15.4 15.4 0 0 1 0-30.8v-.2l.07.2a15.46 15.46 0 0 1 15.31 15.38 15.46 15.46 0 0 1-15.3 15.42z" color="#646464"/>
</icon>

That wouldn’t be too hard to implement, but in my opinion it goes beyond the purpose of the library, so I won’t go there. You would have to make modifications to the icon pack parser and the drawable loader. If you’re interested, you can take a look at my answer on Stack Overflow which covers the subject of creating multi path vector drawables.

1reaction
idrisadetunmbicommented, Feb 14, 2020

The user probably has the responsibility of ensuring the icon they are adding is tintable. It might be enough for the lib to just tint the icon drawable as already done here: https://github.com/idrisadetunmbi/icondialoglib/commit/6131bec0a89a717d52817de2fccb0355f5318ae6#diff-cf7ca223f86ef0063bdb90b1487e37a6R374

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add an image to the "drawable" folder in Android Studio?
Right click on res -> new -> Image Asset; On Asset type choose Action Bar and Tab Icons; Choose the image path; Give...
Read more >
Create app icons with Image Asset Studio - Android Developers
After you open Image Asset Studio, you can add adaptive and legacy icons by following these steps: In the Icon Type field, select...
Read more >
How to Add Image to Drawable Folder in Android Studio?
Step 1: Open Android Studio and go to the app > res > right-click > New > Image Asset as shown in the...
Read more >
Android: Notification Icons - OneSignal Documentation
Adding custom icons to some or all of your notifications. Works with Android (and ... You must add each image with listed size...
Read more >
How to Add Custom Icons to Your Flutter Application
Let's assume we want this image to be our application launcher icon: 1_G3Ro06E4rc6F30BC9n-OBw. First, add the image you would like to use as ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found