Android折叠式工具栏:如何调整文本大小,以使其显示全文而不是部分文字 [英] Android collapsing toolbar: How to resize the text, so that it shows full text than partially

查看:139
本文介绍了Android折叠式工具栏:如何调整文本大小,以使其显示全文而不是部分文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CollapsingToolbarLayout:

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.

推荐答案

首先在styles.xml中定义文本样式

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>

请注意,这些值仅是示例;您需要更改它们以适合您的应用.另外,您可能需要其他TextAppearance样式作为父项.

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.

然后使用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"


/>

使用代码:

collapsingToolbar.setCollapsedTitleTextAppearance(R.style.TextAppearance_MyApp_Title_Collapsed);
collapsingToolbar.setExpandedTitleTextAppearance(R.style.TextAppearance_MyApp_Title_Expanded);


在评论中有关于多行文本的讨论. CollapsingToolbarLayout支持多行文本.请忽略我在工具栏上使用setCustomView()的建议.根据文档:


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.

这篇关于Android折叠式工具栏:如何调整文本大小,以使其显示全文而不是部分文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆