Android 如何获得梯度';s端颜色与MaterialCardView';s的背景色加上“s”;“高程叠加”;(在夜间模式下)?
我正在尝试为我的Android Kotlin应用程序制作一个卡片组件()。为了标题的可读性,我已经将渐变设置在图片的顶部,我希望它的颜色和卡片的背景混合 在日间模式下,卡的背景与Android 如何获得梯度';s端颜色与MaterialCardView';s的背景色加上“s”;“高程叠加”;(在夜间模式下)?,android,android-layout,material-design,android-drawable,Android,Android Layout,Material Design,Android Drawable,我正在尝试为我的Android Kotlin应用程序制作一个卡片组件()。为了标题的可读性,我已经将渐变设置在图片的顶部,我希望它的颜色和卡片的背景混合 在日间模式下,卡的背景与?attr/colorSurface没有区别,因此我将其设置为渐变色endColor。但是,在夜间模式中,有一个“仰角叠加”功能,通过应用colorOnPrimary并在顶部添加一些alha(基于仰角),将卡的背景颜色更改为稍浅的颜色。所以,这件事是改变卡bg的颜色,但不是我的梯度的endColor-梯度保持黑色,而卡b
?attr/colorSurface
没有区别,因此我将其设置为渐变色endColor。但是,在夜间模式中,有一个“仰角叠加”功能,通过应用colorOnPrimary并在顶部添加一些alha(基于仰角),将卡的背景颜色更改为稍浅的颜色。所以,这件事是改变卡bg的颜色,但不是我的梯度的endColor-梯度保持黑色,而卡bg是黑暗的如何使渐变的endColor与具有“高程叠加”的卡bg相同?提前感谢
布局/活动\u main\u article.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="@id/button"
app:layout_constraintDimensionRatio=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription"
tools:srcCompat="@sample/articles_images" />
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/activity_main_article_gradient"
app:layout_constraintBottom_toBottomOf="@id/imageView"
app:layout_constraintEnd_toEndOf="@id/imageView"
app:layout_constraintStart_toStartOf="@id/imageView"
app:layout_constraintTop_toTopOf="@id/imageView" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:maxLines="1"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="@id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@sample/articles_headings" />
<Button
android:id="@+id/button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/activity_main_article_preview"
app:icon="@drawable/ic_outline_remove_red_eye_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageView" />
<Button
android:id="@+id/button2"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/activity_main_article_edit"
app:icon="@drawable/ic_outline_edit_24"
app:layout_constraintBottom_toBottomOf="@id/button"
app:layout_constraintEnd_toStartOf="@id/button3"
app:layout_constraintStart_toEndOf="@id/button"
app:layout_constraintTop_toTopOf="@id/button" />
<Button
android:id="@+id/button3"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/activity_main_article_share"
app:icon="@drawable/ic_outline_share_24"
app:layout_constraintBottom_toBottomOf="@id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/button2"
app:layout_constraintTop_toTopOf="@id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
在GitLab上,链接到相关提交。@GabrieleMariotti感谢您的评论!现在,我所理解的是,这个东西被称为“高程叠加”,它是从colorOnSurface和一些alpha计算出来的,并绘制在colorSurface的顶部。但是我怎样才能把它应用到梯度上呢?另外,我不明白你想说什么关于cardView。对不起,我的不好。你能发布你的主题吗?你定义颜色表面了吗?不用担心!我把我的文件上传到gitlab,所以你可以看到你需要的任何东西。我没有设置自定义颜色表面,只有主/次颜色集。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:startColor="#00000000"
android:endColor="?attr/colorSurface"/>
</shape>