activity_main.xml
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView =(WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.loadUrl("file:///android_asset/www/index.html");
}
i have this code, but javascript is not working :(
Web view acts as an in-built browser which displays the webpages in Android. In other words, Web view turns your application into web application. WebView is an extension of Android's View class. It uses WebKit to display a web page which is a browser engine which provides tools for browsing the web.
Enabling JavaScript in Android BrowserIn the Browser window, click on the menu icon with three vertical lines. Then tap on Settings from the dropdown list. Click on the Advanced button, where you will see Enable JavaScript on the list. Finally, click on the box next to Enable JavaScript to turn it on.
May 18, 2021•HSM ArticleGo to settings > apps and select Chrome application. Tap on Disable (this will disable the chrome browser) Go to Google PlayStore and search for webview. Tap on Android System Webview in the search results.
You've forgot one of the most important ones :
webView.getSettings().setPluginState(PluginState.ON);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With