gpt4 book ai didi

当 textIsSelectable 设置为 true 时,Android TextView 不会更新其文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:54 24 4
gpt4 key购买 nike

我遇到了这个奇怪的问题,让我很头疼很麻烦。

我发布了一个应用程序,它是几本书的存储库,我决定使用 TextView 来显示每一章的文本,因为它符合要求并且快速且易于使用。

用户要求他可以选择一个文本并复制它,我使用 textIsSelectable = true 一切正常,第二天他调用我报告文本没有改变,你打开一个章节然后切换到另一个章节但文本保持不变。

我认为这可能是我这边的一些逻辑问题,但经过一些调试后问题出在 TextView 中,当我设置 textIsSelectable = false;一切都很好。

为了确保我使用了每次显示文本时都会增加的 static int,文本保持不变。

那么问题是什么?我以错误的方式使用 TextView 吗?或者它是 TextView 本身的一些错误?

这是我的布局(txtBody 是导致问题的 TextView)

        <?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:fillViewport="true"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:orientation="vertical"
android:gravity="right">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title Text"
android:id="@+id/txtTitle"
android:textSize="24sp"
android:padding="5dp"
android:gravity="right"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Detail Text"
android:id="@+id/txtBody"
android:background="@android:color/white"
android:gravity="right"
android:textColor="@android:color/black"
android:textSize="16sp"
android:padding="5dp"
android:enabled="true"
android:textIsSelectable="true"
android:selectAllOnFocus="false"
android:soundEffectsEnabled="true"/>

</LinearLayout>


</ScrollView>


</FrameLayout>

我使用这段代码来设置文本:

String body = MainDataManager.getInstance().getChapterBody(book.getTable(), chapter.getId());
updateTextStyle();
txtTitle.setText(chapter.getTitle());
txtBody.setText(body, TextView.BufferType.SPANNABLE);

最佳答案

在更改 textview 的文本之前使用 invalidate() 方法。

 String body = MainDataManager.getInstance().getChapterBody(book.getTable(), chapter.getId());
updateTextStyle();
txtTitle.invalidate();
txtTitle.setText(chapter.getTitle());
txtBody.invalidate();
txtBody.setText(body, TextView.BufferType.SPANNABLE);

关于当 textIsSelectable 设置为 true 时,Android TextView 不会更新其文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14785848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com