Java Code Examples for android.app.Activity#getActionBar()

The following examples show how to use android.app.Activity#getActionBar() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static Object setActionBarUpIndicator(Object info, Activity activity,
        Drawable drawable, int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    final SetIndicatorInfo sii = (SetIndicatorInfo) info;
    if (sii.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            sii.setHomeAsUpIndicator.invoke(actionBar, drawable);
            sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set home-as-up indicator via JB-MR2 API", e);
        }
    } else if (sii.upIndicatorView != null) {
        sii.upIndicatorView.setImageDrawable(drawable);
    } else {
        Log.w(TAG, "Couldn't set home-as-up indicator");
    }
    return info;
}
 
Example 2
@TargetApi(11)
private static String getToolbarTitle(Activity activity) {
    try {
        ActionBar actionBar = activity.getActionBar();
        if (actionBar != null) {
            if (!TextUtils.isEmpty(actionBar.getTitle())) {
                return actionBar.getTitle().toString();
            }
        } else {
            if (activity instanceof AppCompatActivity) {
                AppCompatActivity appCompatActivity = (AppCompatActivity) activity;
                android.support.v7.app.ActionBar supportActionBar = appCompatActivity.getSupportActionBar();
                if (supportActionBar != null) {
                    if (!TextUtils.isEmpty(supportActionBar.getTitle())) {
                        return supportActionBar.getTitle().toString();
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 3
public static void initActionBar(final Activity activity) {
    if (activity == null) {
        return;
    }

    ActionBar bar = activity.getActionBar();
    if (bar == null) {
        return;
    }

    if (activity instanceof MainActivity) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM
                | ActionBar.DISPLAY_SHOW_HOME);
    } else {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP
                | ActionBar.DISPLAY_SHOW_CUSTOM);
    }
}
 
Example 4
Source Project: Bitocle   File: PullToRefreshAttacher.java    License: Apache License 2.0 6 votes vote down vote up
protected EnvironmentDelegate createDefaultEnvironmentDelegate() {
    return new EnvironmentDelegate() {
        @Override
        public Context getContextForInflater(Activity activity) {
            Context context = null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                ActionBar ab = activity.getActionBar();
                if (ab != null) {
                    context = ab.getThemedContext();
                }
            }
            if (context == null) {
                context = activity;
            }
            return context;
        }
    };
}
 
Example 5
Source Project: weex   File: ScreenShot.java    License: Apache License 2.0 6 votes vote down vote up
public static  int getActionBarHeight(Activity activity) {
    int actionBarHeight = 0;
    if(activity.getActionBar()!= null){
        actionBarHeight = activity.getActionBar().getHeight();
    }

    if (actionBarHeight != 0)
        return actionBarHeight;

    final TypedValue tv = new TypedValue();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (activity.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "android.support.v7.appcompat.R.attr.actionBarSize");

        }

        else if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)){
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
            Log.e("actionBarHeight==",actionBarHeight +  "actionBarHeight is android.R.attr.actionBarSize");

        }
    }

    return actionBarHeight;
}
 
Example 6
public static SetIndicatorInfo setActionBarDescription(SetIndicatorInfo info, Activity activity,
        int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    if (info.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            info.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
            if (Build.VERSION.SDK_INT <= 19) {
                // For API 19 and earlier, we need to manually force the
                // action bar to generate a new content description.
                actionBar.setSubtitle(actionBar.getSubtitle());
            }
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
        }
    }
    return info;
}
 
Example 7
public static Object setActionBarDescription(Object info, Activity activity,
        int contentDescRes) {
    if (info == null) {
        info = new SetIndicatorInfo(activity);
    }
    final SetIndicatorInfo sii = (SetIndicatorInfo) info;
    if (sii.setHomeAsUpIndicator != null) {
        try {
            final ActionBar actionBar = activity.getActionBar();
            sii.setHomeActionContentDescription.invoke(actionBar, contentDescRes);
        } catch (Exception e) {
            Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
        }
    }
    return info;
}
 
Example 8
Source Project: droidtestrec   File: MenuProcessor.java    License: Apache License 2.0 6 votes vote down vote up
public void processActivity(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar != null) {
        processActionBar(actionBar);
    } else if (activity instanceof AppCompatActivity) {
        android.support.v7.app.ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (supportActionBar != null) {
            processSupportActionBar(supportActionBar);
        }
    }

    ViewGroup menuView = findActionBar(activity);
    if (menuView != null) {
        processMenuView(menuView);
    }
}
 
Example 9
Source Project: androidtestdebug   File: CameraFragment.java    License: MIT License 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Add an up arrow to the "home" button, indicating that the button will go "up"
    // one activity in the app's Activity heirarchy.
    // Calls to getActionBar() aren't guaranteed to return the ActionBar when called
    // from within the Fragment's onCreate method, because the Window's decor hasn't been
    // initialized yet.  Either call for the ActionBar reference in Activity.onCreate()
    // (after the setContentView(...) call), or in the Fragment's onActivityCreated method.
    Activity activity = this.getActivity();
    ActionBar actionBar = activity.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
 
Example 10
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean hideActionBar(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar == null || !actionBar.isShowing()) return false;
    actionBar.hide();
    return true;
}
 
Example 11
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 12
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Add an up arrow to the "home" button, indicating that the button will go "up"
    // one activity in the app's Activity heirarchy.
    // Calls to getActionBar() aren't guaranteed to return the ActionBar when called
    // from within the Fragment's onCreate method, because the Window's decor hasn't been
    // initialized yet.  Either call for the ActionBar reference in Activity.onCreate()
    // (after the setContentView(...) call), or in the Fragment's onActivityCreated method.
    Activity activity = this.getActivity();
    ActionBar actionBar = activity.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
 
Example 13
Source Project: zhangshangwuda   File: ActionBarWrapper.java    License: Apache License 2.0 5 votes vote down vote up
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 14
Source Project: Noyze   File: ConfigurationActivity.java    License: Apache License 2.0 5 votes vote down vote up
public static void setupActionBar(Activity activity) {

        // Tint the status bar, if available.
        SystemBarTintManager tintManager = new SystemBarTintManager(activity);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setTintColor(activity.getResources().getColor(R.color.action_bar_dark));

        ActionBar actionBar = activity.getActionBar();
        if (null != actionBar) {
            actionBar.setIcon(DateUtils.AppIcon());
            actionBar.setDisplayHomeAsUpEnabled(!activity.isTaskRoot());
            actionBar.setDisplayShowTitleEnabled(true);
        }
    }
 
Example 15
Source Project: zen4android   File: ActionBarWrapper.java    License: MIT License 5 votes vote down vote up
public ActionBarWrapper(Activity activity) {
    mActivity = activity;
    mActionBar = activity.getActionBar();
    if (mActionBar != null) {
        mActionBar.addOnMenuVisibilityListener(this);

        // Fixes issue #746
        int displayOptions = mActionBar.getDisplayOptions();
        mActionBar.setHomeButtonEnabled((displayOptions & DISPLAY_HOME_AS_UP) != 0);
    }
}
 
Example 16
public static Object setActionBarUpIndicator(Object info, Activity activity,
        Drawable drawable, int contentDescRes) {
    final ActionBar actionBar = activity.getActionBar();
    if (actionBar != null) {
        actionBar.setHomeAsUpIndicator(drawable);
        actionBar.setHomeActionContentDescription(contentDescRes);
    }
    return info;
}
 
Example 17
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static boolean showActionBar(Activity activity) {
    ActionBar actionBar = activity.getActionBar();
    if (actionBar == null || actionBar.isShowing()) return false;
    actionBar.show();
    return true;
}
 
Example 18
Source Project: mytracks   File: Api14Adapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void configureActionBarHomeAsUp(Activity activity) {
  ActionBar actionBar = activity.getActionBar();
  if (actionBar != null) {
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
}
 
Example 19
Source Project: PictureChooser   File: API11Wrapper.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean hasActionBar(final Activity a) {
    return a.getActionBar() != null;
}
 
Example 20
Source Project: mytracks   File: Api11Adapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setTitleAndSubtitle(Activity activity, String title, String subtitle) {
  ActionBar actionBar = activity.getActionBar();
  actionBar.setTitle(title);
  actionBar.setSubtitle(subtitle);
}