Android如何更改应用程序的黑色默认背景颜色
问题描述:
我尝试了所有我可以做的事情,但它似乎需要不同的方法来更改黑色默认的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>
我试图改变背景颜色,但它仍然是黑色的。
答
尝试使用:
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颜色“透明”,如下
android:background="@android:color/transparent"
并设置线性或相对布局background #689f38