我使用以下设置在toolbar.xml 中设置我的工具栏主题:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimaryDark"
android:elevation="4dp"
app:title="@string/app_name"
>
</android.support.v7.widget.Toolbar>
在布局 my_layout.xml 中:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<include
app:title="@string/my.toolbar.title"
layout="@layout/toolbar"
>
</include>
</LinearLayout>
不幸的是,工具栏的标题没有获取my.toolbar.title的值。
http://developer.android.com/training/improving-layouts/reusing-layouts.html#Include建议您可以覆盖任何 android: 属性,但是 app: 呢?
注意:我也尝试过使用 android:title 而不是 app:title 但仍然没有成功。
有什么想法吗?
最佳答案
您可以通过编程来完成:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Your title");
关于android - 使用toolbar.xml 的include 时无法设置工具栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30977875/