![](/img/trans.png)
[英]Android custom title bar, does not work with android:label from manifest
[英]Android - How to set title for custom Toolbar in Manifest file? Label attribute doesn't work
我在应用中使用自定义工具栏小部件,发现清单文件中的label属性不起作用。 除了在Activity / Fragment中使用“ setTitle()”方法外,还有其他建议吗? 谢谢。
<activity
android:name=".CartActivity"
android:label="@string/cart_activity_label"
android:parentActivityName=".CatalogActivity" />
我希望可以通过使用清单文件中的属性来显示标题。
在工具栏小部件中使用textview,或者如果您正在使用支持库,请使用setsupportActionbar(toolbar); 在你的活动中。
getActionBar().setTitle(R.string.logout);
或更好,
getSupportActionBar().setTitle(R.string.logout);`
在onCreate方法中
好的...我刚刚发现我忘记了将View(工具栏)对象链接到View ID。 Follwing是将工具栏用作默认ActionBar的完整设置:
private Toolbar toolbar;
toolbar = findViewById(R.id.toolbar); //I missed this
setSupportActionBar(toolbar);
工具栏标题说明:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.