Using a background color for a view with some alpha (e.g. #99fe0038) and some elevation on API 21 reveals two circles: one for the view itself and another inside:
Elevation and background color are set via code:
view.setElevation(getResources().getDimensionPixelSize(R.dimen.fab_elevation_lollipop));
view.setBackgroundColor(Color.parseColor("#99fe0038"));
Without setting elevation or with using an opaque color everything looks like expected.
Is it an Android bug or have I missed something here?
Removing shadow effect worked for me.
FAB.setShadow(false);
FAB.setBackgroundColor(getResources().getColor(R.color.fab_transparent));
Related
Want this kind of shadow effect with android card view except for white background with cardview property, neither use with the canvas draw mechanism nor 9 patch image mechanism
want to use only drawable shape or cardview properties. TIA
EDIT: There is this github project you can use to get custom shadow for CardView. Just implement it in your project and use this instead of androidx components. Link: https://github.com/nvl2val/CardView/tree/master
2nd EDIT: Also another workaround for this issue. Read this thread: Android change Material elevation shadow color
I don't really get your question but CardView itself has a lot of properties you can play with. Check this documentation for more: https://developer.android.com/reference/androidx/cardview/widget/CardView
Using elevation will give you shadow by default so if you don't want a shadow on objects with a white background you need to set the elevation to 0. Here you can play with
android:elevation = "10dp"
app:cardElevation = "10dp"
and see which one does the job better for you. Also, try adding some padding to your parent layout so that CardView has some space around. All this and maybe more you can find in this answer: https://stackoverflow.com/a/46374054/14759470
I want to make the android chip background color to transparent.
From material version higher than 1.1.0,
we need to set app:chipBackgroundColor="#color/transparent" but also app:chipSurfaceColor="#color/transparent"
Ok, I see. But how can it do by kotlin code?
background color can be set by code below...
chipBackgroundColor = ColorStateList.valueOf(ContextCompat.getColor(context, android.R.color.transparent))
But, I can't find the code that changes its surface color!!
Is there any solution?
chip.chipBackgroundColor = getColorStateList(your color)
How to implement shadows like the image below?
I try many ways as CardView, elevation, many custom views, drawable. But that was different from the wanted shadows.
CardView
elevation of CardView is ambient light + key light. But, I want just ambient light elevation.
I Want this shadow.
Starting with API 28 you can set the color of the shadows.
If you want the ambient shadow only, then you need to set the color of the key light(aka spot light) to transparent.
You can do so by adding the following to your view tag in xml:
android:outlineAmbientShadowColor="#android:color/transparent"
Now only key/spot light will show.
and for ambient shadow
android:outlinesSpotShadowColor="#android:color/transparent"
Also check
setOutlineAmbientShadowColor() and setOutlinePostShadowColor()
to do it programmatically
You can also set them to other colors if you don't want a black shadow.
I'm using the lasted support design : 28, alpha3.
I use using the "Theme.MaterialComponents.Light.NoActionBar" as the theme for my application and "MaterialButton" instead of a normal "Button" in my layouts.
I can set the BackgroundTind from the XML as normal but i can't change it via java.
I tried:
deliverSwitch.setBackgroundTintList(getResources().getColorStateList(R.color.colorYellow));
deliverSwitch.setSupportBackgroundTintList(getResources().getColorStateList(R.color.colorYellow));
but none of them worked... I also tried to clear the current tint by leaving the setBackgroundTintList null and it doesn't work either.
I couldn't get it working either. As a workaround I did the following: First you get the current background Drawable, then you tint it with the desired color and set the new background with setBackgroundDrawable for your Material Button.
Drawable background = materialButton.getBackground();
background.setTint(ContextCompat.getColor(getContext(), R.color.bg_button_primary));
materialButton.setBackgroundDrawable(background);
I hope that helps.
Hey I would like to know how i can added such a faded color effect to my layout any help is appreciated. An example here:
Thanks
You can create a Shape Drawable with your desired gradient and set it as a background for your information view at the bottom
You can use setAlpha() method to adjust alpha level for your views and thereby get a faded effect.For handling this in xml you can use android:alpha attribute for your view.