如何更改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.