Set to Background - Android android.app

Android examples for android.app:Activity

Description

Set to Background

Demo Code

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 {//from  w  ww . ja  v  a 2 s  . c om
      view.setBackgroundResource(res_back_h);
    }
  }

  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