Answer the question
In order to leave comments, you need to log in
How does loadDataWithBaseURL work?
There is an assets folder, it contains a screen.png picture and a MainActiviy with the following code:
package webviewtest.webviewtest;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = (WebView) findViewById(R.id.webView);
String data = "<html><body><img src=\"screen.png\" style=\"display:block;margin-left:auto;margin-right:auto;position:relative;top:50%;margin-top:-101px;\"></body></html>";
view.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "utf-8", null);
view.setWebViewClient(new WebViewClient());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question