[英]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.