java - Androidx 迁移后 MaterialCardView 不会受其样式影响
问题描述
我正在开发新的 android 应用程序,该应用程序使用谷歌材料设计组件显示咖啡饮料。在我将项目迁移到 Androidx 后,样式将不适用于 MaterialCardView IDK 有什么问题或为什么会发生这种情况!!。
我尝试使用最新的材料库版本升级我的 gradle 文件,并在网上搜索找不到任何类似的问题。
<!--this is the card layout:-->
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coffee_card"
style="@style/CoffeeItemStyle"
android:layout_width="180dp"
android:layout_height="200dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="@dimen/cardview_margin"
android:layout_marginRight="16dp"
android:layout_marginBottom="@dimen/cardview_margin">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/coffee_image"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/coffee_drink_image"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/coffee_name"
style="@style/CoffeeNameStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="Name"
app:layout_constraintBottom_toTopOf="@+id/coffee_image"
app:layout_constraintStart_toStartOf="@+id/coffee_image"
app:layout_constraintTop_toBottomOf="@+id/coffee_image"
app:layout_constraintVertical_bias="0.82" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<!--this is the style(CoffeeItemStyle):-->
<style name="CoffeeItemStyle" parent="Widget.MaterialComponents.CardView">
<item name="cardBackgroundColor">@android:color/white</item>
<item name="cardCornerRadius">@dimen/cardview_radius</item>
<item name="cardElevation">@dimen/cardview_elevation</item>
<item name="android:clickable">true</item>
<item name="android:stateListAnimator">
@animator/shr_next_button_state_list_anim
</item>
</style>
我希望卡片视图出现在 4dp 半径、8dp 高度、白色背景并在点击卡片视图时更改 Z 轴。
解决方案
推荐阅读
- javascript - 复选框未在带有 javascript 消息的 Gridview 中触发
- java - 对象序列化时netty编解码器可以发送包吗
- azure - Azure 服务总线队列分区队列 AutoRenewTimeout
- neo4j - 将 Neo4j 2.3 升级到 3.4 - 无法访问 jarfile 2.x-config-migrator.jar
- go - 将密码从 []byte 转换为 string 时 go package wincred 添加空格
- java - Pattern.matcher() 究竟是如何工作的?
- ruby-on-rails - Rails - 将数据库信息更改为环境变量时出现迁移错误 - AWS
- javascript - 如何将 ES6 JSON 对象转换为字典?
- node.js - 为什么自制程序在链接仅桶装公式时要求我添加 --force 选项?
- java - 如何在使用 JavaComm lib 从计算机(调制解调器)拨号到手机时获得音频通量