【问题标题】:How to fetch different html file in a single WebView in android studio如何在 android studio 的单个 WebView 中获取不同的 html 文件
【发布时间】:2017-07-23 21:57:08
【问题描述】:
我是一个初学者,我正在尝试为一本书制作一个应用程序,该书有 15 章,每章都有 25 个主题。在主要活动中,我想要 15 个带有 ch 的按钮。名称,当单击一个按钮时,它会转到另一个具有 25 个带有主题的按钮的活动,当单击一个主题时,它会从 assets 文件夹中获取一个 html 文件并将其显示在一个具有 webview 的新活动中。现在我的问题是,当在同一个活动上单击按钮时,我如何获取相应的 html 文件?或者我必须为每个主题使用差异活动。这将是非常冗长(超过 300 个)的活动。
【问题讨论】:
标签:
android
html
android-activity
webview
【解决方案1】:
You should save the Web view calling method in a Util Class and load URL with corresponding to your Activity
Ex: wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.loadUrl(url);
And Then pass URL as String to your activity
eg. String url = ed1.getText().toString();