Android Studio中的背景无效

时间:2016-05-06 17:48:37

标签: android background

我正在尝试将图片设置为我的应用的背景。我在Android Studio预览中看到它,但如果我在手机上加载应用程序(Android 5),我看不到图像。这是代码。我是Android界的新手。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="lorenzobenevento.mydomotics.MainActivity"
    android:background="@drawable/background">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

提前致谢,抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

协调器布局就像一个framelayout。你放在里面的所有内容都将放在任何小部件的前面,并在之前定义。

重要的是,这意味着xml文件中的所有内容:

<include layout="@layout/content_main" />

将位于您在协调器布局中定义的背景图像的前面。有可能是掩盖内容,所以请考虑在该xml文件中设置背景图像。