Android 中未显示工具栏标题
Toolbar title not showing in Android
我有这个工具栏:
<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");
当我 运行 应用程序时,工具栏显示但不显示标题。我怎样才能显示标题?谢谢
尝试从应用清单文件设置标题。尝试
<activity
android:name=".MainActivity"
android:label="@string/title_activity"/>
然后在您的字符串值资源中设置字符串值 属性。
检查以下 link 及其相关答案。
希望对您有所帮助!!
您可以在 CollapsingToolbarLayout 中包含这一行
app:titleEnabled="false"
我有这个工具栏:
<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");
当我 运行 应用程序时,工具栏显示但不显示标题。我怎样才能显示标题?谢谢
尝试从应用清单文件设置标题。尝试
<activity
android:name=".MainActivity"
android:label="@string/title_activity"/>
然后在您的字符串值资源中设置字符串值 属性。
检查以下 link 及其相关答案。
希望对您有所帮助!!
您可以在 CollapsingToolbarLayout 中包含这一行
app:titleEnabled="false"