2016-03-25 8 views
3

I RecyclerViewの項目を表し、リソースファイル内の次のXMLコードを、持っている:android.support.v7.cardview:cardBackgroundColorが動作しない

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:android.support.v7.cardview="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android.support.v7.cardview:cardBackgroundColor="#9e9e9e" 
    android.support.v7.cardview:cardElevation="7dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/transparent" 
      android:orientation="vertical"> 
      <ImageView 
       android:id="@+id/type" 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:layout_gravity="end" /> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 
       <TextView 
        android:id="@+id/field_name" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:padding="2dp" 
        android:textColor="#000000" 
        android:textSize="20sp" 
        android:typeface="monospace" /> 
       <LinearLayout 
        android:layout_width="15dp" 
        android:layout_height="match_parent" /> 
      </LinearLayout> 
      <LinearLayout 
       android:id="@+id/main_recyclerview_item_actions" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="end" 
       android:visibility="gone"> 
       <Button 
        android:id="@+id/delete" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/delete" 
        android:textColor="@color/colorAccent" 
        style="@style/Widget.AppCompat.Button.Borderless"/> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

問題はCardViewは決してないということです以下の画像のように9e9e9e: 色は白コードに問題がある

enter image description here

9e9e9eされていない色を取得しますか?そして、私はこの問題をどうやって解決できますか?

+0

card_view:cardBackgroundColor = "#9e9e9e" withroid.support.v7なしで試しましたか? –

+0

非常に良い。私はそれを変更し、カードは色を持っています。ありがとうございました。 –

+0

私はあなたがもちろん欲しいなら、私が助けてくれれば答えることができます:) –

答えて

1

android.support.v7

とセットを削除するようにしてくださいのみ

card_view:cardBackgroundColor="#9e9e9e"

希望すると助かります!

0

あなたが好きこのコードを変更することができます:

android.support.v7.cardview:cardBackgroundColor="@color/myColor" 

、その後Strings.xmlフォルダに移動し、次の行を追加します。

<color name="myColor">#e9e9e9</color> 
+0

はい、彼はこれをモディファイすることができますが、あなたの答えが彼の問題を解決する方法は? –

+0

同様の問題がありました。直接カラーコードを追加しても機能しませんでしたが、この方法を使用して問題を解決しました。 – hTony

+0

あなたは 'string.xml'を意味するのではなく、スタイルですか? – Vucko

3

cardBackgroundColor属性を削除し、android:background="#9e9e9e"をレイアウトの最初のLinearLayoutに設定するだけです。私はこの方法を意味する:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:android.support.v7.cardview="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android.support.v7.cardview:cardElevation="7dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#9e9e9e" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/transparent" 
     android:orientation="vertical"> 

     <ImageView 
      android:id="@+id/type" 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:layout_gravity="end" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/field_name" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:padding="2dp" 
       android:textColor="#000000" 
       android:textSize="20sp" 
       android:typeface="monospace" /> 

      <LinearLayout 
       android:layout_width="15dp" 
       android:layout_height="match_parent" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/main_recyclerview_item_actions" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="end" 
      android:visibility="gone"> 

      <Button 
       android:id="@+id/delete" 
       style="@style/Widget.AppCompat.Button.Borderless" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="DELETE" 
       android:textColor="@color/colorAccent" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

0
app:cardBackgroundColor="@color/cv_bgcolor" 

は私のために働きました。

関連する問題