簡體   English   中英

如何將textView中的Text設置為.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);

希望這會幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM