在安卓系统(cardView)中,我很难改变卡片的背景颜色。
我在XML中做到了这一点:
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_margin="5dp"
android:layout_gravity="bottom"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
card_view:cardBackgroundColor="#2600e622">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">但它并没有起作用。我一直默认使用白色背景色。
我不确定从这里到哪里去。有什么想法吗?
还有-我想把卡片放在屏幕的中央,卡片最终在屏幕的中央,但在屏幕的顶部。我可以了解一下如何将卡放在屏幕中央吗?
谢谢。
发布于 2016-06-29 21:44:12
这应该是可行的。
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="5dp"
android:layout_gravity="center"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
card_view:cardBackgroundColor="#00490b">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
// add more views here
</RelativeLayout>
</android.support.v7.widget.CardView>发布于 2016-06-29 21:46:19
我使用以下代码以编程方式设置:
card.setCardBackgroundColor(Color.WHITE);或者在XML中,您可以使用以下代码:
card_view:cardBackgroundColor="@android:color/white"发布于 2017-10-11 03:34:41
如果你的colors.xml中有这个颜色,例如:
<color name="ambar400">#FFCA28</color>
在你的类中使用:
card_name.setCardBackgroundColor(getResources().getColor(R.color.ambar400));
https://stackoverflow.com/questions/38101252
复制相似问题