【发布时间】:2018-08-07 17:21:23
【问题描述】:
一段时间以来,我一直在尝试将一个大字符串(25k+ 个字符)设置为 TextView,但我得到了“STRING_TOO_LARGE”输出。
我在某处读到在运行时设置字符串可能有助于解决该问题,所以我修改了我的代码,但这似乎没有帮助。我也尝试直接在setText() 中设置资源ID,但也没有做任何事情。
我在Activity 中使用以下方法显示terms_dialog:
private void showTermsPopup() {
Dialog termsDialog = new Dialog(this);
termsDialog.setContentView(R.layout.terms_dialog);
termsDialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
// Cancel the dialog if you touch the background
termsDialog.setCanceledOnTouchOutside(true);
// Add the terms string to the dialog
TextView termsText = termsDialog.findViewById(R.id.termsTextView);
String terms = getResources().getString(R.string.terms);
termsText.setText(terms);
// Show the dialog
termsDialog.show();
}
这是terms_dialog.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:padding="8dp"
android:scrollbarSize="0dp">
<TextView
android:id="@+id/termsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</android.support.constraint.ConstraintLayout>
this 是我得到的结果(敏感信息被涂白)。
【问题讨论】:
-
@HB。所以我可能应该将字符串添加到文本文件中并从那里读取它?