首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何删除TextView中第一个字母前的空格

如何删除TextView中第一个字母前的空格
EN

Stack Overflow用户
提问于 2020-11-05 17:59:10
回答 1查看 112关注 0票数 0

所以我有3个垂直对齐的TextViews。第二个有一个更大的字体。

现在,如果第二个TextView包含一个以'B‘开头的字符串,则该视图看起来是缩进的:

下面是我的XML布局:

代码语言:javascript
运行
复制
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView style="@style/TextAppearance.LabelSmall"
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView1" />

        <TextView style="@style/TextAppearance.LabelBig"
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="B TextView2" />

        <TextView style="@style/TextAppearance.LabelSmall"
            android:id="@+id/text3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView3" />
    </LinearLayout>

下面是相应的styles.xml文件:

代码语言:javascript
运行
复制
<resources>
    <style name="TextAppearance.LabelBig" parent="TextAppearance.MaterialComponents.Headline3">
        <item name="fontFamily">@font/opensans_regular</item>
        <item name="android:fontFamily">@font/opensans_regular</item>
        <item name="android:textSize">48sp</item>
    </style>

    <style name="TextAppearance.LabelSmall" parent="TextAppearance.MaterialComponents.Body1">
        <item name="fontFamily">@font/opensans_regular</item>
        <item name="android:fontFamily">@font/opensans_regular</item>
        <item name="android:textSize">16sp</item>
    </style>
</ressources>

有没有办法让这些TextViews看起来同样缩进?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-11-05 18:34:54

您不需要为单行文本使用三个文本视图,只需使用spannable。

在这里找到一些信息:https://medium.com/androiddevelopers/spantastic-text-styling-with-spans-17b0c16b4568

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64694873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档