目前它只显示应用程序的名称,我希望它显示一些自定义的东西,在我的应用程序中的每个屏幕都是不同的。
例如:我的主屏幕可以在操作栏中显示“page1”,而应用程序切换到的另一个活动可以在该屏幕操作栏中显示“page2”。
目前它只显示应用程序的名称,我希望它显示一些自定义的东西,在我的应用程序中的每个屏幕都是不同的。
例如:我的主屏幕可以在操作栏中显示“page1”,而应用程序切换到的另一个活动可以在该屏幕操作栏中显示“page2”。
当前回答
getSupportActionBar)。setTitle(“头衔”);
其他回答
我们可以用以下两种方式之一更改动作栏标题:
In the Manifest: in the manifest file, set the label of each Activity. android:label="@string/TitleWhichYouWantToDisplay" In code: in code, call the setTitle() method with a String or the id of String as the argument. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { setTitle(R.string.TitleWhichYouWantToDisplay); // OR You can also use the line below // setTitle("MyTitle") setContentView(R.layout.activity_main); } }
只需在onCreate方法中添加此代码。
setTitle("new title");
getSupportActionBar)。setTitle(“头衔”);
试着这样做……
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setTitle(String.format(your_format_string, your_personal_text_to_display));
setContentView(R.layout.your_layout);
...
...
}
这对我很有用
年纪大一点,但也有同样的问题。我是这样做的:
strings.xml
<字符串
确保你在AndroidManifest.xml中设置了这个:
<activity
...
android:label="@string/title_awesome_app" >
...
</activity>
这很简单,你不必担心空引用和其他东西。