如何将 textView 中的文本设置为 .txt 文件中的文本

How to set the Text in textView to a text in .txt file

如果我有一个TextView,例如:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView"
    android:textColor="#999999"
    android:layout_marginTop="10dp"
    android:text="@text/text.txt"/>

如何将文本设置为该 .txt 文件中的文本。 或者有其他选择吗?

我认为无法直接将 .txt 文件分配给 XML 中的 textview。但是您可以通过 java 动态读取 .txt 文件。要阅读 .txt 文件,请将您的 .txt 文件放在 /assets 目录中,然后这样访问...

AssetManager assetMananger = context.getAssets();
InputStream inputStream = assetMananger.open("file.txt");
System.out.println(inputStream);

希望对您有所帮助。