Here is a step by step guide to inserting HTML code into your app in Sketchware.
Step 1
Start new project and fill details in project settings.
Start new project and fill details in project settings.
Step 2
In your app View in Main.xml or any other page where you want to insert HTML code, insert webview widget.
In your app View in Main.xml or any other page where you want to insert HTML code, insert webview widget.
Step 3
Now go to Logic of your page (MainActivity.java for Main.xml) and in onCreate event use following block:
WebView ......... loadUrl .............
Now go to Logic of your page (MainActivity.java for Main.xml) and in onCreate event use following block:
WebView ......... loadUrl .............
Now fill this block as below:
WebView webview1 loadUrl data:text/html, <html > <title> </title> <body> Write your HTML code here. </body> </html>
WebView webview1 loadUrl data:text/html, <html > <title> </title> <body> Write your HTML code here. </body> </html>
Step 4
Also add onBackPressed event and use following blocks:
If webview1 canGoBack
WebView webview1 goBack
else
FinishActivity
Step 4
Save and Run your app. Your app will show contents of your HTML code at the place where webview is located.
Also add onBackPressed event and use following blocks:
If webview1 canGoBack
WebView webview1 goBack
else
FinishActivity
Step 4
Save and Run your app. Your app will show contents of your HTML code at the place where webview is located.
You can use CSS and JavaScript in your code. You can insert links to gif and images.
To enable the links in the HTML code, and to enable JavaScript in the HTML code, insert the following code using code injection technique in Sketchware:
WebSettings webSettings=webview1.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); }
To enable the links in the HTML code, and to enable JavaScript in the HTML code, insert the following code using code injection technique in Sketchware:
WebSettings webSettings=webview1.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); }
why '#' character not support in html?
ReplyDelete