Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android CardView自定义样式属性_Android_Xml_Android Cardview_Android Styles_Cardview - Fatal编程技术网

Android CardView自定义样式属性

Android CardView自定义样式属性,android,xml,android-cardview,android-styles,cardview,Android,Xml,Android Cardview,Android Styles,Cardview,我读了很多关于这方面的其他问题,比如,或者,但是没有人为我工作 我需要创建一个自定义样式的表单CardView。这是我的代码: style.xml <resources > ... <style name="CardViewStyle" parent="CardView"> <item name="app:cardBackgroundColor">#d9edf7</item> </style>

我读了很多关于这方面的其他问题,比如,或者,但是没有人为我工作

我需要创建一个自定义样式的表单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>
    <?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>

它很好用。但我需要使用自定义样式。


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="6dp"
    tools:context="in.a.a.a.a">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView_sylb"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:lineSpacingExtra="8sp"
            android:padding="5dp"
            android:text="Coming soon"
            android:textAlignment="textStart"
            android:textIsSelectable="false"
            android:textSize="14sp"
            android:typeface="serif" />


    </android.support.v7.widget.CardView>


</ScrollView> 

不要在cardview中设置主题而不是样式

改变这个

android:theme="@style/CardViewStyle"


这就是工作。

我将cardview放在scrollView中
android:theme="@style/CardViewStyle"
style="@style/CardViewStyle"