I am building a CardView with a transparent background, and am running into an issue with trying to set the cardBackgroundColor to be one with an alpha channel.
Here is what I've tried:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/list_view_btn"
android:layout_width="@dimen/icon_size"
android:layout_height="@dimen/icon_size"
android:layout_gravity="bottom|start"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/icon_bottom_margin"
card_view:cardBackgroundColor="#66F9F9F9"
card_view:cardCornerRadius="3dp"/>
The result is a CardView button that has no transparency what-so-ever (but with the F9F9F9 grey color, ignoring the 66 alpha value). So, next step was to try doing this programmatically:
mListBtn.setPreventCornerOverlap(false);
int baseColor = getResources().getColor(R.color.material_gray);
mListBtn.setCardBackgroundColor(Color.argb(50,
Color.red(baseColor),
Color.green(baseColor),
Color.blue(baseColor)));
This is the result:
Notice there is a padding between the center and the border. The CardView is empty with no child views in it, and I tried this with/without the setPreventCornerOverlap() call to see if this was the issue... Can anybody explain why this is happening to me?
1) Why does the XML definition of my CardView with cardBackgroundColor ignore alpha coloring
2) Why does setting the cardBackgroundColor programmatically cause the coloring to work, but now there is a padding implicitly added?