How to show static html page in android emulator?

I want to display one static HTML page in my Android emulator.

+4
source share
3 answers

I assume you want to display your own page in a webview?

Create this as your activity:

public class Test extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView webview = new WebView(this); setContentView(webview); try { InputStream fin = getAssets().open("index.html"); byte[] buffer = new byte[fin.available()]; fin.read(buffer); fin.close(); webview.loadData(new String(buffer), "text/html", "UTF-8"); } catch (IOException e) { e.printStackTrace(); } } } 

This will read the index.html file from your project resource / folder.

+8
source

A simpler method is described in the Android HTML resource with links to other resources . His work is wonderful for me.

Put the HTML file in the "assets" folder in the root, upload it using:

 webView.loadUrl("file:///android_asset/filename.html"); 
+11
source

That way, you can simply use the WebView control to display web content on the screen, which can view the WebView control as a browser view.

You can also dynamically formulate an HTML string and load it into a WebView using the loadData () method. This requires three arguments. String htmlData, String mimeType and String encoding

First of all, you create the file test.html and save it in the resources folder.

The code:

 <html> <Body bgcolor="yellow"> <H1>Hello HTML</H1> <font color="red">WebView Example by Android Devloper</font> </Body> </html> 

if you want to see the full source code: Show HTML content on Android

0
source

All Articles