Santhosh
Santhosh

Reputation: 11798

Android collapsing toolbar: How to resize the text, so that it shows full text than partially

I am using CollapsingToolbarLayout:

I am using the following code to show the title:

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

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

enter image description here

Upvotes: 6

Views: 5594

Answers (1)

kris larson
kris larson

Reputation: 30985

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 to fit your app. Also, you may want a different TextAppearance style 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: In the comments there is a discussion about multi-line text. CollapsingToolbarLayout does not support multi-line text. Please ignore my suggestion to use setCustomView() on the toolbar. According to docs:

Do not manually add views to the Toolbar at run time. We will add a 'dummy view' to the Toolbar which allows us to work out the available space for the title. This can interfere with any views which you add.

Upvotes: 12

Related Questions