简体   繁体   中英

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. This is the code. I'm new in Android world.

<?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:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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