[英]Android - How to set title for custom Toolbar in Manifest file? Label attribute doesn't work
I'm using a custom Toolbar widget in my app, I found that the label attribute in Manifest file doesn't work. 我在应用中使用自定义工具栏小部件,发现清单文件中的label属性不起作用。 Any suggestion except using "setTitle()" method in Activity/Fragment?
除了在Activity / Fragment中使用“ setTitle()”方法外,还有其他建议吗? Thank you.
谢谢。
<activity
android:name=".CartActivity"
android:label="@string/cart_activity_label"
android:parentActivityName=".CatalogActivity" />
I wish the title can be shown by using attributes in Manifest file. 我希望可以通过使用清单文件中的属性来显示标题。
use a textview inside the Toolbar widget or if you are using support library, use setsupportActionbar(toolbar); 在工具栏小部件中使用textview,或者如果您正在使用支持库,请使用setsupportActionbar(toolbar); in your activity.
在你的活动中。
getActionBar().setTitle(R.string.logout);
or better, 或更好,
getSupportActionBar().setTitle(R.string.logout);`
in onCreate method 在onCreate方法中
Ok...I just found out that I forgot to link the View (Toolbar) object to the View id. 好的...我刚刚发现我忘记了将View(工具栏)对象链接到View ID。 Follwing is the complete setup for using a Toolbar as a default ActionBar:
Follwing是将工具栏用作默认ActionBar的完整设置:
private Toolbar toolbar;
toolbar = findViewById(R.id.toolbar); //I missed this
setSupportActionBar(toolbar);
Toolbar title explain: 工具栏标题说明:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.