android - CollapsingToolbarLayout 标题显示错误
问题描述
我有以下代码,我不知道为什么折叠工具栏后标题没有正确显示。检查文本“T. My tanatory”。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?android:attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/iv_tanatorio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/t_tanatory"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/myToolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_tanatosalas"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
解决方案
您忘记在活动 onCreate 中设置工具栏
setSupportActionBar(findViewById<Toolbar>(R.id.myToolbar))//Kotlin
setSupportActionBar(findViewById(R.id.myToolbar) //java
推荐阅读
- c - 如果他们没有输入正确的变量类型,我需要我的程序告诉用户“无效条目...”
- php - 如何在`array_reduce`中改变这个数组
- objective-c - 构建 react-native App 时缺少“@end”错误
- c - 有副作用的功能
- date - 两个日期之间的月份列表作为月份和年份
- javascript - fullPage.js 没有缓动
- lit-element - lit-element styles within html template versus static styles getter?
- javascript - Remove from JS object where key value is an empty array
- azure - How to get character matches in Azure Search index instead of substrings
- python - 有没有办法生成项目列表的所有唯一排列