在 webview android 中加载文本文件
到目前为止,我已经阅读了如何在 webview 中加载“正常”html 网页.. 到目前为止,我传递了包含文本文件路径的 URL,但它没有加载任何内容。 这是我的方法:
@Override
public void onSelected(String url) {
ViewerFragment viewer = (ViewerFragment) getSupportFragmentManager()
.findFragmentById(R.id.view_fragment);
if (viewer == null || !viewer.isInLayout()) {
Intent showContent = new Intent(getApplicationContext(),
ViewerFragment.class);
showContent.setData(Uri.parse(url));
startActivity(showContent);
} else {
viewer.updateUrl(url);
}
}
查看器片段得到了这个:
public class ViewerFragment extends Fragment{
private WebView viewer = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (WebView) inflater
.inflate(R.layout.details_fragment, container, false);
return viewer;
}
public void updateUrl(String newUrl) {
if (viewer != null) {
viewer.loadUrl(newUrl);
}
}
}
但继续得到这个屏幕:
有什么想法如何做到这一点? =/ 我已经尝试过谷歌搜索,但没有找到太多关于它的信息......实际上几乎没有找到。因此,任何帮助将不胜感激。
so far i have read how to load "normal" html webpages in a webview ..
so far I pass the URL containing the path of my text file but it loads nothing.
this is my method:
@Override
public void onSelected(String url) {
ViewerFragment viewer = (ViewerFragment) getSupportFragmentManager()
.findFragmentById(R.id.view_fragment);
if (viewer == null || !viewer.isInLayout()) {
Intent showContent = new Intent(getApplicationContext(),
ViewerFragment.class);
showContent.setData(Uri.parse(url));
startActivity(showContent);
} else {
viewer.updateUrl(url);
}
}
and the viewer fragment got this:
public class ViewerFragment extends Fragment{
private WebView viewer = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (WebView) inflater
.inflate(R.layout.details_fragment, container, false);
return viewer;
}
public void updateUrl(String newUrl) {
if (viewer != null) {
viewer.loadUrl(newUrl);
}
}
}
but keep getting this screen:
any ideas how to do this? =/ I already tried googling a bit but didnt find much info about it... actually found almost none. So any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试读取文本文件的内容并在文本前添加
前缀,然后附加
然后使用
WebView
方法loadData(...)
。例子:
Try reading the contents of the text file and prefixing the text with
<html><body>
then append</body></html>
then use theWebView
methodloadData(...)
.Example: