2017-08-11 113 views
0

我嘗試了所有我可以做的事情,但它似乎需要不同的方法來更改黑色默認的blackground的顏色。Android如何更改應用程序的黑色默認背景顏色

這裏是圖片:http://imgur.com/a/CkQGX

下面是代碼:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#EE7469" 
    android:orientation="horizontal"> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_margin="8dp" 
    card_view:cardUseCompatPadding="true" 
    card_view:cardCornerRadius="10dp" 
    android:background="#689F38" 
    card_view:cardElevation="5dp" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/list_item_string" 
     android:layout_centerVertical="true" 
     android:layout_alignParentStart="true" 
     android:paddingStart="8dp" 

     android:textSize="18sp" 
     tools:textSize="12sp" 
     android:background="#689F38"/> 

    <!-- ADDED SPACER VIEW --> 
    <View 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#689F38" 
     android:layout_weight="1" 
     /> 
    <!-- /ADDED SPACER VIEW --> 

    <Button 
     android:layout_marginTop="10dp" 
     android:id="@+id/delete_btn" 
     android:layout_width="30dip" 
     android:layout_height="30dip" 
     android:layout_gravity="right" 
     android:background="@android:drawable/ic_delete"/> 

    <Button 
     android:layout_marginTop="10dp" 
     android:id="@+id/edit_btn" 
     android:layout_width="30dip" 
     android:layout_height="30dip" 
     android:layout_toStartOf="@id/delete_btn" 
     android:layout_gravity="right" 
     android:layout_marginRight="40dp" 
     android:background="@android:drawable/ic_delete" 
     /> 


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

我試圖改變背景顏色,但它仍然是黑色的。

回答

0

嘗試使用:

card_view:cardBackgroundColor="#689F38" 

那麼代碼是這樣的:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_margin="8dp" 
    card_view:cardUseCompatPadding="true" 
    card_view:cardCornerRadius="10dp" 
    card_view:cardBackgroundColor="#689F38" 
    card_view:cardElevation="5dp" 
    android:layout_height="match_parent"> 

如果你想通過編程修改使用:

your_cardview.setCardBackgroundColor(your_color); 
0

我想這個問題是在充氣在適配器中查看

使用以下代碼在佈局通貨膨脹

View v = inflater.inflate(R.layout.item_layout, parent, false); 
0

可以在cardview使用相對佈局或線性佈局和設置寬度和高度「match_parent」,並設置cardeview顏色「透明」,如下

android:background="@android:color/transparent" 

並設置線性或相對佈局background #689f38

相關問題