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
Related
A somewhat well-known issue in Android, since Lollipop and the introduction of Material Design, is that elevated Views with see-through backgrounds reveal ugly artifacts from their shadow draws behind them.
Those visual glitches are all caused by the shadows being adjusted for increasing elevation by kind of "zooming out" on the gradients, which causes their inner borders to shrink inward within the View's bounds, normally unseen in ones with opaque backgrounds. No clipping is done there, and every relevant check I've come across in the source turns the shadow off completely when that artifact would be seen, so that clipping is seemingly omitted intentionally, likely for efficiency.
As you might expect, many questions have been posted about it here over the years, but turning it off or somehow avoiding it altogether seem to be about the only generally effective solutions other users have found, as well:
How to set semi transparent background color for Android CardView?
CardView background alpha colour not working correctly
Cardview - rounded corners with transparent background
Elevation + transparency bug on Android Lollipop
How to create a shape with a transparent background and a shadow, but the shadow should not be visible behind the shape outline?
CardView with transparent background issue on > API 21
Weird view behavior when an elevation and a transparent background color are used on API 21
Remove background colour from FloatingActionButton
Android Floating Action Button Semi Transparent Background Color
How to set border and background color of Floating Action Button with transparency through xml?
How to center image in FloatingActionButton behind transparent background?
How to remove those dark circular background from floating action button?
Android transparency and Shadows
a shadow appear below material button after setting background color tint in android
Multiple layers of shadows in android recyclerview elevation
How to adjust shadow in translucent navbar?
Transparent white button looks bad in Android Material Design
Various bespoke workarounds are available for a few common setups, some users ignore it or don't realize what it is, and some have even integrated the effect into their designs, but I still have not found a single example where it's been truly fixed. I haven't gone digging into the native graphics code yet, but I also can't find any instance in the SDK source where anything is done about it other than disabling the shadow when that might be visible, and if we're not able to do it at the app level it doesn't really matter what the low-level graphics stuff can do.
There doesn't seem to be much out there about the general problem, but recently I'd shared some information about it on this old question concerning CardView, including a couple of basic techniques for creating clipped shadow replicas as replacements. However, the examples in that answer are quite specific, and adjusting them for multiple different Views would be tedious and error-prone, and would likely require some not-insignificant modifications to an existing setup in order to add them.
Is there any way to apply those workarounds generally, and with minimal changes?
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?
I want to create something close to Material Theme in app that is supposed to work with Android 4.x and 5.x.
I have tried to use Material theme, but I need api 21 for that. My current minimum api is 15 and I want to keep that.
Do I have to create shadows as PNG images or there is easier way?
I want to keep application compatybile with Android 4.x and I have no time to maintain two versions (for Android 4.x and 5.x).
I wouldn't call it an easy way, but you can mimic real animated shadows on any device above Android Cupcake. Here's how it works:
draw your view to an off-screen bitmap with LightingColorFilter set to 0,0
blur the black shape (the off-screen bitmap) using the ScriptIntrinsicBlur class and elevation value as radius
draw the bitmap beneath the view
It requires adding custom elevation attributes, custom views capable of rendering shadows, and using render script and the compatibility library (for older devices).
If you'd like to see that solution in action, check my library:
https://github.com/ZieIony/Carbon
I have this ratingbar which is inside the applications and it is always displaying correctly.
But recently I realise that it is not working correctly on some devices (which include Nexus 5 with Lollipop version). The rating bar are covered by a black overlay as shown on the image below (only on some devices). When listview (with rating stars) is scrolled, the rating bar will be shown (and then black overlay shows again). it only affect the yellow stars but not the white ones.
I am not sure if anyone had ever met this problem before? I am thinking if it is the recent android update on Nexus 5 that causes this as the rating bar works well on other devices.
Accoring to me,
This may be using v21 of the support libraries or possibly unstable OS update as .xml file and code is not available.
These are the issue reported on google for rating bar please check link below,
RatingBar rendering broken on devices
The development team has fixed the issue that you have reported and it
will be available in a future build.
RatingBar w/ Custom Stars Drawable is rendered as 1 stretched star on pre-Lollipop phones
when using v21 of the support libraries, the RatingBar w/ custom stars
renders as expected. With v22, instead of 5 stars, you just get one,
but stretched to match the width that 5 stars should take
First of all, do not use RatingBar#setProgressDrawable because no
matter what platform, it is going to work like #setBackground()
(single stretched image for whole background). Secondly, setting
android:ratingBarStyle on theme level does not work. I ended up
creating custom style, with "android:progressDrawable" and applying it
for every view I needed.
RatingBar does not render in InfoWindow
setting the style to android:attr/ratingBarStyle does not work, and
ratingBarStyleSmall does work
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.