First define your text styles in styles.xml
<style name="TextAppearance.MyApp.Title.Collapsed" parent="android:TextAppearance"> <item name="android:textColor">@android:color/white</item> <item name="android:textSize">11sp</item> </style> <style name="TextAppearance.MyApp.Title.Expanded" parent="android:TextAppearance"> <item name="android:textColor">@android:color/white</item> <item name="android:textSize">14sp</item> </style>
Note that the values ββare just examples; You need to change them according to your application. In addition, a different TextAppearance style may be required as a parent.
Then in XML:
<android.support.design.widget.CollapsingToolbarLayout xmlns:app="http://schemas.android.com/apk/res-auto" . . . app:collapsedTitleTextAppearance="@style/TextAppearance.MyApp.Title.Collapsed" app:expandedTitleTextAppearance="@style/TextAppearance.MyApp.Title.Expanded" />
in code:
collapsingToolbar.setCollapsedTitleTextAppearance(R.style.TextAppearance_MyApp_Title_Collapsed); collapsingToolbar.setExpandedTitleTextAppearance(R.style.TextAppearance_MyApp_Title_Expanded);
EDIT: The comments discuss multi-line text. CollapsingToolbarLayout does not support multiline text. Please ignore my suggestion to use setCustomView() on the toolbar. According to the docs:
Do not manually add views to the toolbar at run time. . We will add a "dummy view" to the toolbar, which will allow us to develop an available space for the name. This can interfere with any views you add.
kris larson
source share