Streetboy
Streetboy

Reputation: 4401

Setting android app background image

i want to set same background image to all my app layouts. My app supports all devices from mini phone to 10.1 tablets.

Is there one way to do this or i need to set for every layout re-sized image that quality would be good.

I found this in one app: app_background.xml in drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffff00" />
</shape>   

Also maybe some one could give me good explanation how to separate design and functions in java.

Thanks.

Upvotes: 3

Views: 20847

Answers (2)

Oleksii Masnyi
Oleksii Masnyi

Reputation: 2912

Use styles to do this.
1. Create a appropriate drawable image for background
2. Create a values/styles.xml file with following content

<style name="AppTheme" parent="android:style/Theme.Black">
      <item name="android:background">@drawable/main_app_bg</item>
   </style>


3. Use theme for whole app in AndroidManifest.xml

<application android:icon="@drawable/icon"
                 android:label="@string/app_name"
                 android:theme="@style/AppTheme">

Upvotes: 13

Shivan Dragon
Shivan Dragon

Reputation: 15219

Well, you can configure a single image to be auto-scaled for each device's screen size, it explains how here:

http://developer.android.com/guide/practices/screens_support.html

The issue with that is that if you want good aspect, you have to make your original image pretty big (as big as the biggest resolution you expect you app to be used on). Then, when scaled down for smaller screens, that big picture will still use up more memory then needed.

In reality there're not so many different resolutions out there, maybe 7-8 major ones. You should make individual background images of sizes specific to each target resolution, then, in your Action's onCreate(...) method you can do something like this to get the curren't device screen resolution:

Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();

and load the proper background for it (adjusting for eventual title and status bar sizes)

Upvotes: 1

Related Questions