Set Auto Background - Android User Interface

Android examples for User Interface:Screen Background

Description

Set Auto Background

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.view.View;

public class Main {
    public static void AutoBackground(Activity activity, View view,
            int res_back_v, int res_back_h) {
        int orient = ScreenOrient(activity);
        if (orient == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { 
            view.setBackgroundResource(res_back_v);
        } else { 
            view.setBackgroundResource(res_back_h);
        }//from  w w w  . jav  a  2  s. c om
    }

    public static int ScreenOrient(Activity activity) {
        int landscape = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        int portrait = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        int width = activity.getWindowManager().getDefaultDisplay()
                .getWidth();
        int height = activity.getWindowManager().getDefaultDisplay()
                .getHeight();
        return width > height ? landscape : portrait;
    }
}

Related Tutorials