Open top menu

Android-Loading HTML Directly into WebView ?

Its  a possible HTML Code run directly on WebView without load URL.


<WebView
        android:id="@+id/WebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>




 MainActivity.java
...................................................................................................................................................................

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;

public class InfoActivity extends Activity
{
    @SuppressLint("NewApi")
@Override
    protected void onCreate(Bundle savedInstanceState)
    {
       
       super.onCreate(savedInstanceState);
getActionBar().setTitle("About");
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

setContentView(R.layout.info_activity);

           
WebView webView = (WebView) findViewById(R.id.WebView);

               
String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";

webView.getSettings().setJavaScriptEnabled(true);
              // load html tag
webView.loadDataWithBaseURL(null, html, mime, encoding, null);

   
               
    }
   
   
    @Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:

finish();

return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onBackPressed() {

super.onBackPressed();
finish();

}

}

Tagged

0 comments