【发布时间】:2018-04-20 02:54:07
【问题描述】:
我读过很多其他关于这些东西的问题,例如 this 或 this 或 this 但没有人适合我。
我需要创建一个自定义样式表单 CardView。这是我的代码:
style.xml
<resources >
...
<style name="CardViewStyle" parent="CardView">
<item name="app:cardBackgroundColor">#d9edf7</item>
</style>
</resources>
my_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/CardViewStyle">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txvDatetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
在我的应用程序 gradle 文件中
compileSdkVersion 26
minSdkVersion 19
targetSdkVersion 26
implementation 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
这不太可能对我有用。没有任何反应,但我没有发现问题。 如果我不使用自定义样式并直接执行:
my_card.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#d9edf7" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txvDatetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
它工作正常。但我需要使用自定义样式。
【问题讨论】:
标签: android xml android-cardview android-styles cardview