下面列出了android.app.ActionBar#setTitle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_service_list);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
actionBar.setTitle(R.string.activity_service_list_title);
}
mManualActivity = getSettingManualActivityClass();
bindMessageService();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_view);
//Determine which post we are showing
KWBApplication application = (KWBApplication) getApplication();
Intent intent = getIntent();
post = application.getPostById(intent.getLongExtra("postId", -1));
//Customize the action bar
ActionBar actionBar = getActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(post.getTitle());
actionBar.setDisplayUseLogoEnabled(false);
}
//Get references to needed UI components
contentView = (WebView) findViewById(R.id.post_content);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ActionBar actionBar = this.getActivity().getActionBar();
if (actionBar != null) {
actionBar.setTitle(this.getTitle(sectionNumber));
}
}
@Override
public void onStart() {
super.onStart();
ActionBar actionBar = getActivity().getActionBar();
actionBar.setTitle(getString(R.string.my_favorites));
actionBar.setIcon(R.drawable.ic_title_favorite);
}
/**
* 设置标题
*
* @param actionBar 标题栏
* @param spannableString 格式化后的标题
*/
public static void setTitle(ActionBar actionBar, SpannableString spannableString) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN && Build.MANUFACTURER.toUpperCase().equals("LGE")) {
actionBar.setTitle(spannableString.toString());
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
actionBar.setTitle(spannableString);
}
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
//view.setBackgroundColor(getResources().getColor(android.R.color.your_color));
// set name of actionbar.
ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.prefTitle_Developer));
}
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
//view.setBackgroundColor(getResources().getColor(android.R.color.your_color));
//view.setBackgroundColor(getResources().getColor(R.color.prefBkg_System));
// set name of actionbar.
ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources().getString(R.string.prefTitle_System));
}
return view;
}
@Override
public void onStart() {
super.onStart();
ActionBar bar = getActivity().getActionBar();
bar.setTitle(getText(R.string.pref));
bar.setIcon(R.drawable.ic_title_pref);
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_service_list);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
actionBar.setTitle(R.string.activity_service_list_title);
}
bindMessageService();
}
@Override
public void onStart() {
super.onStart();
ActionBar actionBar = getActivity().getActionBar();
actionBar.setIcon(R.drawable.ic_title_list);
actionBar.setTitle(getString(R.string.my_drafts));
}
void toggleSelection(ActionBar actionBar, int position, String packageName) {
if (mSelections.contains(packageName)) {
mSelections.remove(packageName);
} else {
mSelections.add(packageName);
}
if (!mSelections.isEmpty()) {
actionBar.setTitle(String.valueOf(mSelections.size()) + mContext.getString(R.string.hide_app_selected));
} else {
actionBar.setTitle(mContext.getString(R.string.hidden_app));
}
notifyItemChanged(position);
}
private void initHomeActionBar ()
{
if (getActivity() != null)
{
ActionBar actionBar = getActivity().getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setTitle(R.string.app_name);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setIcon(R.mipmap.ic_launcher);
}
}
@Override
@SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Get preferences
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(this);
boolean dark =
preferences.getBoolean(Main.PREF_DARK, true);
if (!dark)
setTheme(R.style.AppLightTheme);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
// Enable back navigation on action bar
ActionBar actionBar = getActionBar();
if (actionBar != null)
{
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.settings);
}
}
public final void setActionBarTitle(int resId) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle(resId);
}
}
public final void setActionBarTitle(CharSequence text) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle(text);
}
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// it removes the title from the actionbar(more space for icons?)
// this.getActionBar().setDisplayShowTitleEnabled(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
contentView = new MyView(this);
setContentView(contentView);
ActionBar ab = getActionBar();
ab.setTitle("AcrylicPaint");
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// setSupportActionBar(toolbar);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// XXX ADDED FOR GEOPAPARAZZI
Bundle extras = getIntent().getExtras();
if (extras != null) {
outputFilePath = extras.getString(MediaStore.EXTRA_OUTPUT);
longitude = extras.getDouble(LONGITUDE);
latitude = extras.getDouble(LATITUDE);
altitude = extras.getDouble(ALTITUDE);
}
// XXX END ADDED FOR GEOPAPARAZZI
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.GREEN);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(DEFAULT_BRUSH_SIZE);
// Where did these magic numbers come from? What do they mean? Can I change them? ~TheOpenSourceNinja
// Absolutely random numbers in order to see the emboss. asd! ~Valerio
mEmboss = new EmbossMaskFilter(new float[]{1, 1, 1}, 0.4f, 6, 3.5f);
mBlur = new BlurMaskFilter(5, BlurMaskFilter.Blur.NORMAL);
// if (isFirstTime()) {
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
//
// alert.setTitle(R.string.app_name);
// alert.setMessage(R.string.app_description);
// alert.setNegativeButton(R.string.continue_fuck,
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog,
// int whichButton) {
// Toast.makeText(getApplicationContext(),
// R.string.here_is_your_canvas,
// Toast.LENGTH_SHORT).show();
// }
// });
//
// alert.show();
// } else {
// Toast.makeText(getApplicationContext(),
// R.string.here_is_your_canvas, Toast.LENGTH_SHORT).show();
// }
loadFromIntents();
}
public void restoreActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
protected void setTitle(String title) {
ActionBar bar = getActivity().getActionBar();
if (bar != null) bar.setTitle(title);
}
private void showGlobalContextActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setTitle(R.string.app_name);
}