Android – white border around dark theme cardviews
I have a custom control that extends cardview. I add it to the linear layout so that I can create a card grid. I don't use listview or recyclerview
I want to set the gap between cards in the linear layout, so I define an edge margin
The card layout uses the dark theme. My application uses the default material theme (dark). I'm testing pixel C, Android 6.0.1
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
card_view:cardUseCompatPadding="true"
card_view:cardPreventCornerOverlap="false"
card_view:cardElevation="5dp"
style="@style/CardView.Dark">
<!-- content here -->
</android.support.v7.widget.CardView>
I add them to the list view:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
LinearLayout newLinearLayout = new LinearLayout(this);
newLinearLayout.setLayoutParams(layoutParams);
newLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
mainLayoutContainer.addView(newLinearLayout);
newLinearLayout.addView(mycardlayoutObj);
Classes that use the cardview layout actually extend the cardview itself, such as
public class MyCustomWidgetextends CardView{
public MyCustomWidget(Context context) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_card_view_layout, this);
}
This is what I see. The card content looks good.. dark. But the margins / gaps around the cardview are white. How to make it transparent, and why does the dark card theme behave so well? Besides, what will shadows look like on such a dark theme?
resolvent:
Therefore, I have a layout file, including < cardview > as described above. My custom class expands this layout and extends cardview. Therefore, I have a cardview in cardview. The "external" card view, that is, the view extended by my custom class, has never set a subject, so it uses the default "light" theme
Because I created this widget programmatically, I think I need to extend cardview. This is wrong
Before:
public class MyCustomWidget extends CardView
After:
public class MyCustomWidget extends LinearLayout{
public MyCustomWidget(Context context) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_card_view_layout, this);