是否有方法将主题应用于Cardview?我不想将这种风格应用到我正在创建的每个视图中。
这是我现在的CardView:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Custom.Widget.CardView">
<-- I don't want to define the style every time -->
</android.support.v7.widget.CardView>和我的styles.xml
<style name="Custom.Widget.CardView" parent="CardView">
<item name="cardBackgroundColor">@color/card_backgroundColor</item>
<item name="cardCornerRadius">12dp</item>
<item name="cardUseCompatPadding">true</item>
<item name="contentPadding">4dp</item>
</style>我想将样式添加到themes.xml中,以便将其应用于每个Cardview,但我不知道如何应用。甚至可以从支持库中获得视图吗?
当我向themes.xml添加以下内容时,会收到一个警告:no resource found that matches the given name: attr 'Cardview'
<item name="Cardview">@style/Custom.Widget.CardView</item>发布于 2020-08-04 13:42:02
有可能,我也花了很长时间才找到。下面是一个示例,如果整个应用程序都使用MyStyle样式,则将橙色背景应用于所有的卡视图。
在themes.xml
<style name="MyStyle" parent="Theme.AppCompat">
...
<item name="cardViewStyle">@style/MyStyle.Cardview.Orange</item>
</style>
<!-- CardView -->
<style name="MyStyle.Cardview.Orange" parent="CardView">
<item name="cardBackgroundColor">#F3921F</item>
</style>发布于 2017-05-12 02:13:37
我也在我的项目中使用这个,没有问题,也许你没有在你的build.gradle中添加这个。
compile 'com.android.support:cardview-v7:25.2.0'https://stackoverflow.com/questions/38737423
复制相似问题