如何为 RelativeLayout 边框添加背景颜色?

How to add background color to RelativeLayout borders?

我想向我的 RelativeLayout borders 显示 background color #df0031 以便我的整个 Android screen 将具有 background #df0031,包括现在为白色的边框。

请查看上面的屏幕截图并帮助我以这种方式更新我的 XML,以便 Android Screen 的边框将 background color #df0031 与屏幕的其余部分匹配,而不是#ffffff.

布局(XML):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.sitemakers.sitemakers.HomeFragment"
android:background="@color/colorBgHome"
>

<TextView
    android:id="@+id/home_heading"
    android:layout_marginTop="10dp"
    android:text="WE CREATE AWESOME WEB SITES"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorTextHome"
    />
<TextView
    android:layout_below="@+id/home_heading"
    android:id="@+id/home_text"
    android:layout_marginTop="28dp"
    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut 
    enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
    aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit 
    in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorTextHome"
    />
    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/main_device_image"
    android:textColor="@color/colorTextHome"
    />
</FrameLayout>

Colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorBgHome">#df0031</color>
    <color name="colorTextHome">#ffffff</color>
</resources>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.sitemakers.sitemakers.MainActivity"
tools:showIn="@layout/app_bar_main">

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

感谢您的宝贵时间。

在您有填充的片段容器中。删掉就行了。

编辑您的 content_main 文件以删除导致白色边框的填充。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="in.sitemakers.sitemakers.MainActivity"
tools:showIn="@layout/app_bar_main">

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

从 content_main.xml 中删除这些行:

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

您必须删除填充!删除这些行:

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"