如何更改android的动作条标题和图标 [英] How do I change the android actionbar title and icon

查看:158
本文介绍了如何更改android的动作条标题和图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一些事情的操作栏的安卓

I'm trying to do some things on the Action Bar in Android

我已经在右侧的操作栏添加新项目

I've already added new items in the right side of the action bar

我如何更改操作栏的左边?我想改变的图标和文字,我想在动作栏添加一个后退按钮,为其他画面

How can I change the left side of the action bar? I want to change the icon and the text, and I want to add a "Back Button" in the action bar for the other screens

在此先感谢

推荐答案

这是很容易做到

如果你想在code更改,请致电:

If you want to change it in code, call:

setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);

和值设置为任何你请。

或者Android清单XML文件中:

Or, in the Android manifest XML file:

<activity android:name=".MyActivity" 
       android:icon="@drawable/my_icon" 
       android:label="My new title" />  

要启用后退按钮在您的应用程序使用的:

To enable the back button in your app use:

 getActionBar().setHomeButtonEnabled(true);
 getActionBar().setDisplayHomeAsUpEnabled(true);

在code都应该放置在你的的onCreate ,使标签/图标变化是对用户透明的,但在现实中,它可以在任何地方在被称为活动的生命周期。

The code should all be placed in your onCreate so that the label/icon changing is transparent to the user, but in reality it can be called anywhere during the activity's lifecycle.

这篇关于如何更改android的动作条标题和图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆