We are trying to move all our app icon resources to VectorDrawables to reduce the size of the app and manage the app icon kit easily.
We already have an Icon Kit with all the icons of our app, all in a black color and the idea is to use them and tint in each usage with the appropriate color. This works (more or less) perfectly until you try to made the same in a layer-list/selector/similar, where you need to include an item with a <bitmap> or similar and... I don't find how to tint a VectorDrawable that also works in <21 devices
The pre-requisite is to not need to make it programmatically, I know that is possible but made it programmatically breaks all the easy usage of the icons and, also, not has sense.
In resume, Is there any form to use VectorDrawable in a <Bitmap> XML and tint it working in <21 devices and not programmatically?
The short answer: No, you can't do that.
The extended version:
Copy the SVG and apply color:
icon_a.xml
icon_b.xml (with color changed)
Related
I want to use the default launcher icon provided in android studio as an ImageView. I used the android:src="#drawable/ic_launcher_background" XML tag in my imageView
But I got this as the result:
But I want this in my ImageView:
you are setting ic_launcher_background for this ImageView and you got it
till Android 7 app icon was a single image, oftenly called ic_launcher. Oreo introduced Adaptive Icons, which have two layers - background and icon/logo itself. so you need two ImageViews or LayerDrawable, the second/top layer will be your icon/logo (ic_launcher_foreground? inspect your drawable or mipmap folders)
note that background layer may get some cuts in device launcher - may be square, but also round, rounded corners all or only one etc. also foreground/icon itself may move a bit, just like visualised under above link - when you use old icon ic_launcher on newer devices it won't be exacly same as shown in device launcher
Try this
android:src="#mipmap/ic_launcher"
Hope this helps...Feel free to ask for clarifications...
The default icon provided by the android studio is actually a combination of two different drawable. See the below picture (you can check the same in your project). You can use the icon as an ImageView by stacking one of the drawable on top of another (which is not a good idea) or you can also directly use android:src="#mipmap/ic_launcher". Just as #Vishnu said.
I am trying hard to get rid of the extra margin around the ic launcher icons generated by Android Studio without luck. I know this is one of Google's material design trends. Though, the icons are so small on devices which is ugly.
I have Googled for around three hours and the only workaround I could find is to generate the clipart with a transparent background and photoshop the background with rounded corners which is pretty slow.
Is there a better solution than this?
Thank you.
Per the Designing adaptive icons blog post, the adaptive icon images created in the drawable directory for use on API 26+ devices follow the adaptive icon size and shape:
You'll note that while the entire image must be 108dp by 108dp, the actual visual area is only the center 72dp - the outer edge is only seen when dragging the icons around (where parallax effects may cause it be visible).
The Pixel Launcher, as well as many third party launchers, enforce the use of adaptive icons on API 26+ devices, so you should always design with that requirement in mind - the alternative, in the Pixel Launcher's case for instance, is to place your non-adaptive icon within a white circle.
Therefore you should always design your icon such that the background layer takes up the full size, but any foreground image you put on top of that background layer should be contained within that center area.
You can't just remove that margin without the foreground image being messed up, but as per the Implementing Adaptive Icons follow up blog post, you can remove any white excess around the foreground by putting your trimmed image within a transparent drawable of 108dp x 108dp by using an InsetDrawable.
<!-- Center a 54x54dp image in the 108x108dp size of adaptive icons -->
<inset
android:drawable="#mipmap/ic_fg_trimmed"
android:insetLeft="25%"
android:insetTop="25%"
android:insetRight="25%"
android:insetBottom="25%" />
Although this would have to be something you'd need to do to the ic_launcher_foreground image yourself after the fact.
A better solution, in most cases, is to use vector drawable images as the input to the Android Studio Image Asset wizard - this will ensure they are always the right size and don't take up any additional space in your APK.
I think i had the same problem as you. I solved this with a nasty hack, in the AndroidManifest.xml I just changed the roundIcon to point to the standard icon.
<application
…
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher"
See more from the docs.
When I am adding transparent png icons/images, their color schema changes to "monochrome white", i.e. all the colors but white change to white as on the image:
Most of devices were working well so far, it happens not often.
I am not sure if that's related to the image format, OS version or device, but probably someone already bumped into similar thing.
The images are added as AndroidResource as drawable and have different resolution versions. (I am using Xamarin Android, but not sure if that's related to the issue).
The issue is happening as when the image is added to widgetTab.Layout as menu item as just setting up ImageView.
Any thoughts?
The number pickers in Android contain a shadow above the previous and next value(s). Is there a attribute to make this shadow transparent?
If an image is being used as the background, these shadows are distracting.
Edit:
Running emulator with Android version 6.0.
Setting the solidColor attribute makes the shadows appear in different colors. Unfortunately, setting it to transparent still keeps the black fading appearance.
How this renders during emulation with the background image:
I think it's just the Android version is too old. I didn't do any customization to numberpicker and it still looks flat (no ugly shadow like that). My test device running 6.0
I have realized that there are at least two background colors on Option menu of Android. On the HTC Hero, the background is white and on Samsung Galaxy S II, the background is black.
This became a problem when I set the icons for the background menus. Is there some way to detect the background color of the Option menus in Android?
Possible solutions:
Don't use icons.
Design icons according to the guidelines - http://developer.android.com/guide/practices/ui_guidelines/icon_design_menu.html. There are three different guidelines for up to 2.2 (white background), 2.3 (black background) and 3.0+, so it's a lot of work...
As Profete162 suggested, use #android:drawable/ic_menu_*
For Android 4.0+, you can also set the light / dark Holo theme, which is guaranteed (at least in theory) to remain unchanged across different phone manufacturers - so it'll look the same in HTC Sense, Samsung TouchWiz etc.
That's indeed a very annoying issue.
On my implementation, I always try to use standards icons from android.R.drawable.IC_menu_*, so I am sure these icons are part of the framework and users are always positively surprised to see their generic icons in my app!
That gives a really good continuity in the user experience on the device, but that doesn't answer your question, but at least provide a workaround.
Here are for instance all android 2.2 icons: http://androiddrawableexplorer.appspot.com/
You can trust me, using these icons will always fit your colors.
First of all to answer your title question:
You can reference and read the background of the options menu by reading the attributes of the current theme. The attribute for this is panelFullBackground. E.g. set it as the background of a textview in XML¹:
<TextView android:background="?android:attr/panelFullBackground"
... />
Note that the background seems to be a solid color, but it's not - it's actually a bitmap. If you look closely you can see a grey border at the top (android 2.3+), or a drop shadow (<= android 2.2), so its'a bit difficult. Luckily there is a different attribute called panelColorBackground which matches the background color of the drawable as close as possible. So if you want just the normal background color, use this instead.
¹ This can surely also be read from code, but I don't know how from the top of my head at the moment, maybe I'll look it up and edit it in later.
Regarding icons
So you have the color as stated above, but you still have to process it to know if it's a dark or a bright color. You can do that, but that's not the usual way to deal with these icons and probably a good bit of work until you cover all the possible cases - not to mention that you have to create icons for each variant.
Normally you should adopt the platform menu icon style. This works across all devices and looks familiar to your users (custom icons that dont follow this often look "wrong" - e.g. astro file manager does this I believe).
You can do that by hand (see the guidelines), but the way better alternative is the Android Asset Studio.
It comes in two flavors:
As a webapp
Integrated in the latest version of the ADT plugin for eclipse
(under File->New->Other->Android Icon Set)
The workflow for both is pretty similar, select the point "Menu Icon" and follow the wizard. It will promt you to enter a simple, black and white bitmap of your desired icon that just outlines it's shape. After you specified one, the asset studio will generate everything for you. Play a bit around with the "clipart" option, that has a few example bitmaps ready to see how it works. When finished, the webapp gives you a simple zip which can be extracted into your project directory, the eclipse version adds it directly to the project that you select in the wizard.
The background color can be anything, because its implemented in Framework by manufacturer. You can't read it, in fact you will never need to read it.
Just create your custom menu layout in res/menu folder, set style and use it.