make a webview with a static local webpage, via "datauri"

This commit is contained in:
Alexander Mahr 2024-10-08 12:00:10 +02:00
parent 3a9ac9f73f
commit 1a1b53aaa6

View file

@ -8,26 +8,22 @@ import android.text.method.ScrollingMovementMethod;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.*; import android.view.*;
import android.widget.*; import android.widget.*;
import android.webkit.WebView;
import android.webkit.*;
import android.view.ViewGroup.*; import android.view.ViewGroup.*;
import android.util.Base64;
public class ExampleApp extends Activity { public class ExampleApp extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// creating LinearLayout WebView myWebView = new WebView(this);//activityContext);
LinearLayout linLayout = new LinearLayout(this); WebViewClient myWebViewClient= new WebViewClient();
// specifying vertical orientation myWebView.setWebViewClient(myWebViewClient);
linLayout.setOrientation(LinearLayout.VERTICAL); String unencodedHtml = "<!DOCTYPE html><html><h1> this is html <h1> <h2> this is a h2</h2></html>";
// creating LayoutParams String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(),Base64.NO_PADDING);
LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); myWebView.loadData(encodedHtml, "text/html", "base64");
// set LinearLayout as a root element of the screen //myWebView.loadUrl("https://alexmahr.de/ru");
setContentView(linLayout, linLayoutParam); setContentView(myWebView);
LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(this);
tv.setText("SUPERVIEalexW");
tv.setLayoutParams(lpView);
linLayout.addView(tv);
} }
} }