Android examples for User Interface:ActionBar
setup ActionBar
/* ActivityHelper.java//ww w. j a v a2s. c om * See the file "LICENSE.md" for the full license governing this code. */ import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Build; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; public class Main{ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private static void setupActionBar(Activity activity, String title, Drawable icon) { ActionBar bar = activity.getActionBar(); bar.setBackgroundDrawable(Appearance.ACTIONBAR_BACKGROUND); bar.setTitle(title); // Hack to set the actionbar text to white int actionBarTitleId = Resources.getSystem().getIdentifier( "action_bar_title", "id", "android"); TextView actionBarTextView = (TextView) activity .findViewById(actionBarTitleId); if (actionBarTextView != null) { actionBarTextView.setTextColor(Color.WHITE); } bar.setDisplayHomeAsUpEnabled(false); if (icon != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setActionBarHomeIcon(bar, icon); // bar.setDisplayHomeAsUpEnabled(true); } else { bar.setDisplayShowHomeEnabled(false); } } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private static void setActionBarHomeIcon(ActionBar bar, Drawable icon) { bar.setIcon(icon); } }