CollapsingToolbarLayout Android 中的多行扩展标题?
Multiline expanded title in CollapsingToolbarLayout Android?
如何在 CollapsingToolbarLayout
中制作多行标题,例如..
微信
我的XML文件
<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:background="@color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/HeaderTitleStyle"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/cover_image"
android:layout_width="match_parent" android:layout_height="@dimen/detail_backdrop_height"
android:background="@color/white"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
android:src="@drawable/default_clg_image"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
expandedTitleTextAppearance
app:expandedTitleTextAppearance="@style/HeaderTitleStyle"
这是我的style.xml
<style name="HeaderTitleStyle" parent="@android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">20sp</item>
<item name="android:singleLine">false</item>
</style>
我找到了一个很棒的库,名为 multiline-collapsingtoolbar,它为您提供了一个可以处理多行标题的自定义折叠工具栏。
Usage
The library's public API is identical to the version from the support library, so you can use it as a drop-in replacement.
As the Design Support Library, it should be compatible with API 7
(Android 2.1) and above.
XML layout example:
<android.support.design.widget.AppBarLayout
android:layout_height="192dp"
android:layout_width="match_parent">
<net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"/>
</net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
You can find a simple demo application in the demo
module.
一种更简单的方法是将自定义布局添加到折叠工具栏并在折叠时将其固定,这可能是最终输出:
请查看我关于此的预览answer以查看完整代码
如何在 CollapsingToolbarLayout
中制作多行标题,例如..
微信
我的XML文件
<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:background="@color/white"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/HeaderTitleStyle"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/cover_image"
android:layout_width="match_parent" android:layout_height="@dimen/detail_backdrop_height"
android:background="@color/white"
android:fitsSystemWindows="true"
android:scaleType="fitXY"
android:src="@drawable/default_clg_image"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
expandedTitleTextAppearance
app:expandedTitleTextAppearance="@style/HeaderTitleStyle"
这是我的style.xml
<style name="HeaderTitleStyle" parent="@android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">20sp</item>
<item name="android:singleLine">false</item>
</style>
我找到了一个很棒的库,名为 multiline-collapsingtoolbar,它为您提供了一个可以处理多行标题的自定义折叠工具栏。
Usage
The library's public API is identical to the version from the support library, so you can use it as a drop-in replacement.
As the Design Support Library, it should be compatible with API 7 (Android 2.1) and above.
XML layout example:
<android.support.design.widget.AppBarLayout android:layout_height="192dp" android:layout_width="match_parent"> <net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" app:layout_collapseMode="pin"/> </net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout>
You can find a simple demo application in the
demo
module.
一种更简单的方法是将自定义布局添加到折叠工具栏并在折叠时将其固定,这可能是最终输出:
请查看我关于此的预览answer以查看完整代码