我遇到了一个奇怪的问题,让我很头疼和麻烦。
我发布了一个包含多本书的应用程序,我决定使用TextView来显示每一章的文本,因为它符合要求,而且使用起来快速简便。
用户要求能够选择并复制文本,我使用了textIsSelectable = true,一切都很好,第二天他打电话告诉我文本没有改变,你打开一章然后切换到另一章,但是文本仍然是相同的。
我以为可能是我的逻辑问题,但经过一些调试,问题出在TextView上,当我设置textIsSelectable = false时,一切正常。
为了确保,我使用了一个静态int,在每次显示文本时增加,但文本仍然没有改变。
那么问题是什么?我是否错误地使用了TextView?还是TextView本身存在某些bug?
这是我的布局(txtBody是导致问题的TextView)。
我发布了一个包含多本书的应用程序,我决定使用TextView来显示每一章的文本,因为它符合要求,而且使用起来快速简便。
用户要求能够选择并复制文本,我使用了textIsSelectable = true,一切都很好,第二天他打电话告诉我文本没有改变,你打开一章然后切换到另一章,但是文本仍然是相同的。
我以为可能是我的逻辑问题,但经过一些调试,问题出在TextView上,当我设置textIsSelectable = false时,一切正常。
为了确保,我使用了一个静态int,在每次显示文本时增加,但文本仍然没有改变。
那么问题是什么?我是否错误地使用了TextView?还是TextView本身存在某些bug?
这是我的布局(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);