【发布时间】:2016-02-07 08:10:37
【问题描述】:
我有这个工具栏:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingtoolbarly"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|snap">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
我在 Java 中有这个:
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
myToolbar.setTitleTextColor(0xffffffff);
myToolbar.setBackgroundColor(0xffff0000);
setSupportActionBar(myToolbar);
getSupportActionBar().setTitle("My app");
当我运行应用程序时,工具栏显示但不显示标题。如何显示标题?谢谢。
【问题讨论】:
-
getSupportActionBar().setDisplayShowHomeEnabled(true);试试这个以及你以哪种格式提供颜色值?
-
我试过了,但没用。我的颜色格式是这样的:developer.android.com/reference/android/graphics/…
-
您是否尝试将标题直接设置为 myToolbar?
-
@VivekMishra 你的意思是布局吗?我试过
app:title="My app",没用。另外,尝试了android:title,但也没有用。 -
不喜欢这样 myToolbar.setTitle();
标签: android android-layout android-toolbar