【问题标题】:Can't fully hide android material card background无法完全隐藏android素材卡片背景
【发布时间】:2021-02-25 13:31:20
【问题描述】:

图片how it looks

无法完全隐藏android材质卡背景。我已经搜索并观看了所有可用的视频,但到目前为止没有任何效果。我知道我可以放一些东西来填卡,但我想知道以防万一。

代码:

<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#40000000"
android:clickable="true"
app:cardCornerRadius="30dp"
android:layout_margin="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Planner"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp"
android:fontFamily="@font/nova_bold"/>

<ImageView
android:layout_width="150dp"
android:layout_height="130dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:padding="1dp"
app:srcCompat="@drawable/ic_plan_vec" />

</com.google.android.material.card.MaterialCardView>

【问题讨论】:

  • 你能解释一下什么是excelity问题吗?
  • try -> 背景或backgrounTint app的cardBackgroundColor实例:cardBackgroundColor="@android:color/holo_red_dark"
  • 是的,我已经尝试了所有这些。当我更改颜色的不透明度时,图像中会出现问题,但是当不透明度为 100 时,它只会填满卡片。我希望卡片的背面与烦恼相同。

标签: java android android-studio android-cardview materialcardview


【解决方案1】:

请在您的 XML 中使用 app:cardBackgroundColor="@color/yourColor" 或者在你的java代码中card.setCardBackgroundColor(YourColor);而不是默认的setBackgroundColor()

更新

通过android:alpha="0.4" 更改android:backgroundTint="#40000000" 的不透明度

【讨论】:

  • 是的,当卡片上没有设置不透明度时它可以工作,但是当我设置不透明度时,边框和背面不会像图像显示的那样混合
  • 不透明度是这个? android:backgroundTint="#40000000"?
  • 是的,就是这样。我现在正在使用 app:cardBackgroundColor="#40000000" 最初的 40 表示 40% 的不透明度
  • 但问题依旧。
  • 它工作......有点。它只是使整张卡片透明,但我会想办法。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-07
相关资源
最近更新 更多