简体   繁体   English

Android Studio中的背景不起作用

[英]Background in Android Studio doesn't work

I'm trying to setup an image as background of my app. 我正在尝试将图像设置为我的应用程序的背景。 I see it in Android Studio preview but if I load the app on my phone (Android 5) I can't see the image. 我在Android Studio预览中看到了它,但是如果我在手机(Android 5)上加载该应用程序,则看不到该图像。 This is the code. 这是代码。 I'm new in Android world. 我是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>

Thanks in advance and sorry for my bad English. 在此先感谢您,我的英语不好。

The coordinator layout is like a framelayout. 协调器布局就像框架布局。 Everything you put inside will be in front of what ever widgets and such are defined before it. 您放入的所有内容都将位于之前已定义的小部件之前。

Importantly for you that means everything in the xml file: 对您而言重要的是,这意味着xml文件中的所有内容:

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

will be in front of the background image you've defined in the coordinator layout. 将位于您在协调器布局中定义的背景图像的前面。 Chances are the content in there is covering up, so consider setting the background image in that xml file instead. 可能是其中的内容被掩盖了,因此请考虑在该xml文件中设置背景图像。

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

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