Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

public class Main {
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public static void setBackground(Activity activity, int background) {

        activity.getActionBar()
                .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

        Drawable draw;
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            draw = activity.getResources().getDrawable(background, activity.getTheme());
            activity.getActionBar().setBackgroundDrawable(draw);
        } else {
            draw = activity.getResources().getDrawable(background);
            activity.getActionBar().setBackgroundDrawable(draw);
        }
    }
}