繁体   English   中英

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

我以为问题是适配器中的视图膨胀

在布局膨胀中使用以下代码

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

您可以在cardview中使用相对布局或线性布局,并设置宽度和高度“ match_parent”,并将cardeview颜色设置为“ transparent”,如下所示

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM