Я прочитал много других вопросов об этом, таких как этот или это или это, но у меня никто не работает.
Мне нужно создать собственный стиль формы CardView. Это мой код:
стиль.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>
В моем файле градиента приложения
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>
Это работает нормально. Но мне нужно использовать собственный стиль.