Gray horizontal line pre lollipop cardview on bottom - android

I am trying to get rid of this gray line on my cardview
I am using a color with a bit of transparency - #40B6F2FC
here is my code
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="0px"
android:divider="#null"
app:cardPreventCornerOverlap="false"
app:cardBackgroundColor="#color/sky_colorBlue_20_percent"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardMaxElevation="2dp"
app:cardUseCompatPadding="true">
Followed the answer of this question https://stackoverflow.com/a/18734605/1599611 but still didnt work.
Is there a way to get rid of this grayline without setting the elevation to zero and using a color with transparency added?

Base from this tracker
https://issuetracker.google.com/issues/37008169
Status: Won't Fix (Intended Behavior) CardView does not support
transparency for its background. This is due to limitations of drawing
shadows using canvas api.

Related

View with gradient shadow

I've been searching for a way to do something like a very simple CSS box-shadow for a view, just like a white paper on a grey background, with the white view having a gradient shadow.
I have already tried to use the attribute:
android:elevation="Xdp"
with a background set, but it's not working. I've tried a lot of solutions but none of them was working.
You should try Cardview
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="4dp"
app:cardElevation="4dp"
android:translationZ="5dp"
app:cardBackgroundColor="#color/grey_100">
And dont forget dependency
compile 'com.android.support:cardview-v7:21.0.+'

Card view shadow is not showing

This is my card_view. I have mentioned card_view:cardElevation.
But still shadow is not showing.
I have searched many links. Everywhere they have mentioned to use card_view:cardElevation.
<android.support.v7.widget.CardView
android:id="#+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#color/white"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true"
app:cardPreventCornerOverlap="false">
</android.support.v7.widget.CardView>
Can you tell what I am missing here?
Read https://developer.android.com/training/material/lists-cards.html
To create a card with a shadow, use the card_view:cardElevation
attribute. CardView uses real elevation and dynamic shadows on Android
5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see
Maintaining
Compatibility.
UPDATE
try adding margin to card if you want to see shadow
check https://developer.android.com/reference/android/support/v7/widget/CardView.html
Set the following attribute in your cardview
card_view:cardUseCompatPadding = "true"
card_view:cardElevation = "5dp"

Shadow of CardView not visible on Android Lollipop

Following code works perfectly on Kitkat, but shadows are not visible in Lollipop.
Actually I can see shadow in Android Studio Preview, but not while running on a device/emulator. I'm using CardView for adapter of ViewPager (android.support.v4.view.ViewPager)
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="6dp">
Actually it also shows shadow in L version, but it is based on elevation so you can't see the shadow if card height is match parent
try adding margin to card if you want to see shadow
Found the solution. I'm able to get the shadow effect using following code.
android:background="#android:drawable/dialog_holo_dark_frame"

Unexecpted white frame around Cardview on KitKat but not on Lollipop

I have an unexplained white frame of 1 or 2 dp thick around my cardview on kitkat. This white frame does not appear on Lollipop, which is what I expect.
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="#+id/podcasts_cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="?attr/colorPrimary"
cardview:cardUseCompatPadding="true"
cardview:cardCornerRadius="3dp"
cardview:cardElevation="5dp">
Please note that colorPrimary theme attribute is dark blue and that i am using :
cardview:cardUseCompatPadding="true"
which takes care of the padding issue over platforms.
I had this problem too. Try calling:
setPreventCornerOverlap(false);
on the CardView. That is what worked for me.
Also - you may not need cardUseCompatPadding = "true"

Strange CardView behaviour

I'm trying to implement simple cardview with semi-transparent background.
<android.support.v7.widget.CardView
android:id="#+id/card_view"
app:cardBackgroundColor="#33FFFFFF"
app:cardCornerRadius="4dp"
android:foreground="#33FFFFFF"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="100dp">
......
</android.support.v7.widget.CardView>
And this is the result in L and preL
android L: (Nexus 5)
Pre L:
Any idea how to fix the pre L to look like L ?
As you can see there are too many borders/strokes surrounding the card.
I'm can guess it relates to shadows and stuff...
Thanks.
Look like it's a known defect in google forums
Thanks to #benhylau for providing implementation for cardview with alpha here
There no possible to color cardview background with #__FFFFF as it ignores the transparency values. need to work with alpha attribute

Categories

Resources