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 {
    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static void setActionBar(Activity activity, int background) {

        // Action Bar Icon
        activity.getActionBar()
                .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

        // Action Bar Background
        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);
        }
    }

    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static void setActionBar(Activity activity, int background, String title) {

        // Action Bar Icon
        activity.getActionBar()
                .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

        // Action Bar Title
        activity.getActionBar().setTitle(title);

        // Action Bar Background
        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);
        }
    }
}