Issue
I'm trying to set the URL for a WebView from the layout main.xml.
By code, it's simple:
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/index.html");
Is there a simple way to put this logic into the layout XML file?
Solution
Since URL is basically a string, you can put it into values/strings.xml file
<resources>
<string name="myurl">http://something</string>
</resources>
then you can use it like this:
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(getString(R.string.myurl));
Answered By - Peter Knego
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.