Android minimize toolbar: how to resize text to display full text than partially

I am using CollapsingToolbarLayout:

I use the following code to show the name:

collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbar.setTitle("Udupi Sri krishna Temple"); 

The text is shown below. It shows only partial and shows .. at the end. Is there a way to control the size so that it displays the full text.

enter image description here

+3
android android-collapsingtoolbar
source share
1 answer

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.

+5
source share

All Articles