Fixed
Status Update
Comments
[Deleted User] <[Deleted User]> #2
The same error is thrown if you try to set a background programatically
myCard.setBackgroundResource(android.R.color.background_dark);
myCard.setBackgroundResource(android.R.color.background_dark);
ad...@gmail.com <ad...@gmail.com> #3
I am also having this issue when trying to set the background to a Drawable with CardView.setBackground(). This worked fine with the 21.0.0-rc-1 version of the CardView support library, but not with 21.0.0.
sh...@gmail.com <sh...@gmail.com> #4
Confirming this as well.
Changing the cardview background programmatically causes an IllegalClassCastException in CardViewEclairMr1.java:147 -->
private RoundRectDrawableWithShadow getShadowBackground(CardViewDelegate cardView) {
return ((RoundRectDrawableWithShadow) cardView.getBackground());
}
Could be me, but shouldn't getShadowBackground() only return Drawable? That way we would have to cast RoundRectDrawableWithShadow to elevation and radius getters and setters, but it would fix this issue.
Changing the cardview background programmatically causes an IllegalClassCastException in CardViewEclairMr1.java:147 -->
private RoundRectDrawableWithShadow getShadowBackground(CardViewDelegate cardView) {
return ((RoundRectDrawableWithShadow) cardView.getBackground());
}
Could be me, but shouldn't getShadowBackground() only return Drawable? That way we would have to cast RoundRectDrawableWithShadow to elevation and radius getters and setters, but it would fix this issue.
ch...@google.com <ch...@google.com>
yb...@google.com <yb...@google.com> #5
CardView uses a custom background drawable to draw the card and shadows so you cannot set the background drawable/color on a card view.
In the next release, we'll add a method to set cardBackgroundColor(int color).
Would that be sufficient for your use case ?
In the next release, we'll add a method to set cardBackgroundColor(int color).
Would that be sufficient for your use case ?
sm...@gmail.com <sm...@gmail.com> #6
That would be sufficient for me; thank you!
ad...@gmail.com <ad...@gmail.com> #7
That sounds like it will solve the case where one needs to set the background to a color. However, IMHO, it would also be convenient to be able to set a Bitmap as the background so that the corners get rounded I *think* this was the behavior in the RC-1 version of the library. I know that it didn't throw an exception.
sm...@gmail.com <sm...@gmail.com> #8
By the way, setBackgroundColor(int color) works perfectly on the second L preview on my Nexus 5 for me. But, it crashes on KitKat.
de...@gmail.com <de...@gmail.com> #9
[Comment deleted]
sh...@gmail.com <sh...@gmail.com> #10
That would be great. Thanks.
I did exactly that yesterday, working fine so far down to Eclair.
I mainly needed the cards to change with the changing app theme (Material and Holo Light and Dark), which the library didn't do either. I guess that is intended, which made not being able to change to background color a real bummer. :)
I did exactly that yesterday, working fine so far down to Eclair.
I mainly needed the cards to change with the changing app theme (Material and Holo Light and Dark), which the library didn't do either. I guess that is intended, which made not being able to change to background color a real bummer. :)
yb...@google.com <yb...@google.com> #11
@showp1984, you can still change the background color via XML (which should cover your case for theme support). See attributes section for details:
https://developer.android.com/reference/android/support/v7/widget/CardView.html
@adam, CardView always used the background to draw so arbitrary background drawables were never supported. I assume in Preview 1, it was not detecting the bug. In the future we may support setting background drawable. No plans for it yet.
@adam, CardView always used the background to draw so arbitrary background drawables were never supported. I assume in Preview 1, it was not detecting the bug. In the future we may support setting background drawable. No plans for it yet.
sh...@gmail.com <sh...@gmail.com> #12
@ #11
Thank you for the hint. I'm not particularly fond of providing a XML for every theme though. This also doesn't allow for custom user colors and is bad for maintainability.
I fixed the issue as proposed in #5 and included the new module in my app.
Happy to know it will be addressed in a future release though.
Thank you for the hint. I'm not particularly fond of providing a XML for every theme though. This also doesn't allow for custom user colors and is bad for maintainability.
I fixed the issue as proposed in #5 and included the new module in my app.
Happy to know it will be addressed in a future release though.
ma...@gmail.com <ma...@gmail.com> #13
Until it's fixed, I use following hack to change background color.
Instead of this (causes IllegalClassCastException):
card.setBackgroundColor(Color.parseColor("#"+color));
I do this:
Drawable d = card.getBackground();
d.setColorFilter(Color.parseColor("#"+color), Mode.MULTIPLY);
card.setBackgroundDrawable(d);
Seems to be working with all devices I tried, i.e. Android Jelly Bean, KitKat. I have not yet had opportunity to test this with Lollipop though.
Instead of this (causes IllegalClassCastException):
card.setBackgroundColor(Color.parseColor("#"+color));
I do this:
Drawable d = card.getBackground();
d.setColorFilter(Color.parseColor("#"+color), Mode.MULTIPLY);
card.setBackgroundDrawable(d);
Seems to be working with all devices I tried, i.e. Android Jelly Bean, KitKat. I have not yet had opportunity to test this with Lollipop though.
ju...@gmail.com <ju...@gmail.com> #14
[Comment deleted]
ju...@gmail.com <ju...@gmail.com> #15
I tested with android Lollipop it does not work no background appears.
Here is the fix I propose :
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
Drawable d = card.getBackground();
d.setColorFilter(colorint, Mode.MULTIPLY);
}else{
childcontentOfCard.setBackgroundColor(colorint);
}
Here is the fix I propose :
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
Drawable d = card.getBackground();
d.setColorFilter(colorint, Mode.MULTIPLY);
}else{
childcontentOfCard.setBackgroundColor(colorint);
}
ma...@gmail.com <ma...@gmail.com> #16
That still isn't working for me. The original white background remains.
ru...@gmail.com <ru...@gmail.com> #17
Not sure why this hasn't been marked as released. CardView currently (I believe as of R21.0.2) has a new method setCardBackgroundColor() that appears to work fine.
ma...@gmail.com <ma...@gmail.com> #18
[Comment deleted]
ma...@gmail.com <ma...@gmail.com> #19
[Comment deleted]
gu...@gmail.com <gu...@gmail.com> #20
I get java.lang.classcast.exception for StateListDrawable. It occurs when i try to scroll the recyclerview while action mode is created.
I've used this library to create multi-selector feature for recyclerviews
https://github.com/bignerdranch/recyclerview-multiselect
This error occurs every time on 4.4.4, but not on 5.0 and occurs at times on 4.1.2.
I've attached the bug report.
I've used this library to create multi-selector feature for recyclerviews
This error occurs every time on 4.4.4, but not on 5.0 and occurs at times on 4.1.2.
I've attached the bug report.
gu...@gmail.com <gu...@gmail.com> #21
Here is the report.
gu...@gmail.com <gu...@gmail.com> #22
Wrapping the CardView in a FrameLayout fixed the issue.
er...@gmail.com <er...@gmail.com> #23
Can you please elaborate on what did you do with FrameLayout to solve the issue ?
I wrapped my CardView in FL and made foll changes in onCreateViewHolder()
View view = LayoutInflater.from( viewGroup.getContext( ) ).inflate( R.layout.card_layout, viewGroup, false );
View cardView = view.findViewById( R.id.card );
PerformanceViewHolder viewHolder = new PerformanceViewHolder( cardView );
return viewHolder;
Now it throws exception - MainApp : onCreate: uncaughtException: thread: ex.toString: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.stack trace:
I wrapped my CardView in FL and made foll changes in onCreateViewHolder()
View view = LayoutInflater.from( viewGroup.getContext( ) ).inflate( R.layout.card_layout, viewGroup, false );
View cardView = view.findViewById( R.id.card );
PerformanceViewHolder viewHolder = new PerformanceViewHolder( cardView );
return viewHolder;
Now it throws exception - MainApp : onCreate: uncaughtException: thread: ex.toString: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.stack trace:
gu...@gmail.com <gu...@gmail.com> #24
Please post your complete `PerformanceViewHolder` code and your fragment `onCreateView().`
Description
Since I installed the SDK published on 17th October this code does not work anymore and I get a new error (see CardView_newSDK_Log)
To see how I implemented the CardView class check CardView_sourceCodeExample.
Since the CardView Library comes with appcompat v7 I would assume it should work back with API Level 7 and higher. The setRadius()-Method should not throw an exception.