![](/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.