Android找到默认背景颜色

时间:2016-12-06 16:28:12

标签: android

我的应用程序带有简单的回收者视图。

布局声明如下

<?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="match_parent">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/contentView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/some_id" />

</RelativeLayout>

我注意到在不同的设备上,recyclerView实际上有不同的背景。在较新的设备中,背景只是白色。在较旧的设备上,背景为浅灰色。

在android studio中,设计视图中的背景颜色为空白。

所以我的问题是,这种灰色的颜色来自哪里?如何将其普遍改为白色?

我显然可以在这个特定视图中添加背景:白色。但有没有办法覆盖系统默认值?

4 个答案:

答案 0 :(得分:9)

您所看到的实际上是活动的背景,而不是Recyclerview,默认情况下是透明的。颜色确实改变了每个Android版本的观看时间。

  

您可以在应用主题中覆盖此内容。

     

首先在values / colors.xml中定义颜色

 <resources>
     <color name="background">#FF0000 </color> 
 </resources> 
  

在res /值中创建一个引用该颜色的themes.xml文件:

<resources>  
    <style name="MyTheme" parent="@android:style/Theme.Light">       
        <item name="android:windowBackground">@color/background</item>  
    </style> 
</resources> 
  

然后在你的AndroidManifest.xml中指定为   您的活动主题。

 <activity
        android:name=".MyActivity"
        android:theme="@style/MyTheme" />

请参阅https://stackoverflow.com/a/10157077/4623782

答案 1 :(得分:5)

Android默认背景颜色

 <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?android:colorBackground">
 </RelativeLayout

使用

 android:background="?android:colorBackground"

答案 2 :(得分:1)

这是因为主题。在res / values / style.xml中指定主题。或在视图定义中手动设置。

<android.support.v7.widget.RecyclerView
    android:id="@+id/contentView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/some_id"
    android:background="@android:color/white"
 />

它将为您提供所有设备的白色背景

答案 3 :(得分:0)

在任何android studio项目中默认设置的背景颜色为#fafafa