My goal is to develop a GUI application on top of a background image with buttons in specific places on the image. The first step is to display the background.
The image can be displayed with resources and is described in several FAQs including this one:
how-to-add-background-image-to-activity
It compiles and runs without errors, but the background is black.
Here is the main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootRL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
</RelativeLayout>
The image has been in png, 9.png, and jpg format with basenames of 'main' and 'background'. It builds but does not display. Making clean and recompiling does not help.
This behavior occurs on both the emulator and on hardware -- an Atmel AT91SAM9M10-G45-EK. The SDK version is 2.0.1.
Thank you for your help.
However, activity can't be run unless it's on foreground. In order to achieve what you want, in onPause(), you should start a service to continue the work in activity.
Go to the 'Photos' app and select the photo you want to use. Click on the share icon on the lower left corner of the screen, then select 'Use as Wallpaper. ' Then choose to set the photo as either the lock screen, home screen or both.
"Allow background activity", under Battery, refers to whether apps are allowed to run in the background (when you're not using them onscreen, or the app is not visible to you) or not.
Problem solved: The code was based on code that had a text view and set up the window dynamically.
The Hello Android example does call setContentView(R.layout.main)
which was the clue I needed.
Of course the background in defined in res/layout/main.xml
so it is necessary to call setContentView(R.layout.main)
to get those settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With