Example usage for android.app Activity getActionBar

List of usage examples for android.app Activity getActionBar

Introduction

In this page you can find the example usage for android.app Activity getActionBar.

Prototype

@Nullable
public ActionBar getActionBar() 

Source Link

Document

Retrieve a reference to this activity's ActionBar.

Usage

From source file:Main.java

@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;//from www .  j  a  va 2s.  c o  m
    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);
    }
}

From source file:Main.java

public static void setupActionBar(final Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // Show the Up button in the action bar.
        activity.getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from  w  ww  .  ja va 2  s  .c  o  m*/
}

From source file:Main.java

/**
 * Removes the action bar from the activity. This only works on API 11+.
 *
 * @param activity/*from www .j ava  2 s . com*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void removeActionBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        activity.getActionBar().hide();
    }
}

From source file:Main.java

/**
 * Hides the activity's action bar/*from   w  w  w .j ava 2  s .  c  o m*/
 *
 * @param activity
 *     the activity
 */
public static void hideActionBar(Activity activity) {
    // Call before calling setContentView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && activity != null) {
        activity.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        activity.getActionBar().hide();
    }
}

From source file:de.ub0r.android.callmeter.CallMeter.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setActivitySubtitle(final Activity a, final String t) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        a.getActionBar().setSubtitle(t);
    }//from  www . ja v  a 2 s  . com
}

From source file:Windows.UI.Xaml.Controls.CommandBar.java

public static void remove(android.app.Activity activity, android.view.Menu menu) {
    //if (!(activity instanceof ActionBarActivity)) {
    android.app.ActionBar mainActionBar = activity.getActionBar();
    if (mainActionBar != null) {
        mainActionBar.hide();//  ww w  .j  av a2 s  . c  o m
        mainActionBar.setTitle(null);
        menu.clear();
        return;
    }
    //}
    //else {
    //    ActionBar actionBar = ((ActionBarActivity)activity).getSupportActionBar();
    //    if (actionBar != null) {
    //        actionBar.hide();
    //        actionBar.setTitle(null);
    //        menu.clear();
    //        return;
    //    }
    //}
}

From source file:Main.java

public static void setHomeButtonEnabled(boolean homeButtonEnabled, Activity activity) {
    /*//from  w  w  w  . j av a2 s.c o  m
    Beginning with Android 4.0 (API level 14), the icon must explicitly be enabled as an action item by calling
    setHomeButtonEnabled(true). In previous versions, the icon was enabled as an action item by default.
     */
    if (Build.VERSION.SDK_INT >= 14) {
        activity.getActionBar().setHomeButtonEnabled(true);
    }
}

From source file:Main.java

public static void initialize(Activity activity, int layout) {
    // Do all sorts of common task for your activities here including:
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    activity.setContentView(layout);/*from ww  w. j  ava 2s .co m*/
    activity.getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
    activity.getActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:Main.java

private static int getSmartBarHeight(Activity activity) {
    ActionBar actionbar = activity.getActionBar();
    if (actionbar != null)
        try {//  w  ww .j  a  v a2 s .  com
            Class c = Class.forName("com.android.internal.R$dimen");
            Object obj = c.newInstance();
            Field field = c.getField("mz_action_button_min_height");
            int height = Integer.parseInt(field.get(obj).toString());
            return activity.getResources().getDimensionPixelSize(height);
        } catch (Exception e) {
            e.printStackTrace();
            actionbar.getHeight();
        }
    return 0;
}

From source file:run.ace.TabBar.java

public static void remove(android.app.Activity activity) {
    //if (!(activity instanceof ActionBarActivity)) {
    android.app.ActionBar mainActionBar = activity.getActionBar();
    mainActionBar.removeAllTabs();// ww w. ja  v a  2 s .  co  m
    mainActionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_STANDARD);
    /*
    if (mainActionBar != null) {
        mainActionBar.hide();
        mainActionBar.setTitle(null);
        mainActionBar.removeAllTabs();
        return;
    }
    */
    //}
    //else {
    //    ActionBar actionBar = ((ActionBarActivity)activity).getSupportActionBar();
    //    if (actionBar != null) {
    //        actionBar.hide();
    //        actionBar.setTitle(null);
    //        actionBar.removeAllTabs();
    //        return;
    //    }
    //}
}