shadow effect in android color cardview - android

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

Related

CardView background color doesn't change even after using app:cardBackgroundColor property

I am making effort to change my cardView background color to a different color other than the default color set in style with the colorSurface property.
I am aware colorSuface is responsible for a cardView color, but it is surprisingly difficult to change it color in XML.
I have tried the following singly and together but there is no effect.
android:background="#color/purple_200"
app:cardBackgroundColor="#color/purple_200"
android:backgroundTint="#color/purple_200"
I will appreciate help.
Here is my styles code
<item name="colorSurface">#color/app10</item>
The reason I don't want to change the colorSurface property is because, that is the default desired color I want for all cardView but in this particular layout, I want to style my row of cardView widgets with tones of a color, unfortunately, it is not responding.
I figured out the issue was the color set to an imageView inside the cardView was overlaying the color of the cardView.
Another possible cause of this kind of behaviour is if the cardView was inside a layout whose elevation (layout) is possibly greater than the cardView.
Thanks #Mike M for asserting that cardView doesn't disappoint in this case.

Making ImageCardview in browse fragment totally transparent

I want to make my cardview totally transparent in browse fragment .But the problem is this default shadow type effect is coming.I have tried everything but its not going away.Anyway it can be removed.
CustomImageCardview cardView = new CustomImageCardview(mContext);
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
cardView.setElevation(0);
cardView.setBackgroundColor(ContextCompat.getColor(mContext , R.color.transperent_color));
cardView.invalidate();
Thanx
CardView has default elevation which is why shadow is displaying. Override that using cardElevation property.
app:cardElevation="0dp"
Try cardView.setCardElevation(0)

Card View background color affects shadow color

I have my Card View set up like this:
android:layout_marginTop="2dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="6dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="10p"
Without a background color my Card View looks perfect like this:
However, when I add the simple property:
card_view:cardBackgroundColor="#xxxxxxxx"
the shadows change significantly in terms of color, transparency, blur etc.
How might I go about fixing this? I tried using a RelativeLayout as the background and changing the color there, so it wouldn't affect the shadows... but that affected the rounded corners.
Any ideas? Thanks for the help!
I ran into the exact same problem and solved it by removing the alpha portion of my hex code.
Example: #AA333333 removing the AA. Of course use the hex color that you need without the alpha.
Your idea of RelativeLayout is a good one. Instead of placing the card view in RelativeLayout, add RelativeLayout as CardView child, and than add its content to RelativeLayout, in your case it look like you got single child: TextView.
So change your TextView background color or place it in a RelativeLayout and change RelativeLayout background color.
As a workaround, since the alpha is the problem, you can try to brigthen the card color (or blend it with the underlying color)
ColorUtils.blendARGB(yourCardColor, Color.WHITE, 0.2f)
Instead of that, set android:background="#hexColor"

How may I add a faded colour effect (screenshot shown)

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.

How to remove Fading effect from Listview?

In my application I use a ListView and I need to remove the cacheColorHint at the bottom and top of the list. I tried to set the cacheColorHint to #00000000 but the have semi-transparent effect at the bottom/top.
Do you if it is possible to remove these effect?
Thanks
I think the problem is not with cacheColorHint. Maybe you are trying to deal with fading edge attribute of the listview.
Add this attribute to your listview and check it out,
android:fadingEdge="none"
EDIT
This attribute is deprecated and will be ignored as of API level 14 (ICE_CREAM_SANDWICH). Use android:fadingEdgeLength="0dp" instead. (from Zsolt Safrany's comment).
Take a look at this great article of Romain Guy: http://www.curious-creature.org/2008/12/22/why-is-my-list-black-an-android-optimization/
However to disable the optimization, simply use the transparent color #00000000 for the cacheColorHint, as you are doing, and set a solid background color on the ListView to replace its default semi-transparent background.

Categories

Resources