Android 如何更改应用程序的黑色默认背景颜色

Android how to change the black default background color of the app

我尽了一切可能,但似乎需要不同的方法来更改黑色默认背景的颜色。

图片如下: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>

我尝试更改背景颜色,但它仍然是黑色。

尝试使用:

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);

我认为问题在于在适配器中膨胀视图

在布局中使用以下代码inflation

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

您可以在 cardview 中使用相对布局或线性布局并设置宽度和高度 "match_parent" 并设置 cardeview 颜色 "transparent" 如下

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

并设置线性或相对布局background #689f38