I have a simple layout that contains a webview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:padding="10dp"
android:layout_alignParentStart="true" />
Inside this webview i loaded some HTML dinamically on the OnCreate Method.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView displayVideo = (WebView)findViewById(R.id.webView);
displayVideo.getSettings().setJavaScriptEnabled(true);
String html = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> <title></title><script src=\"http://code.jquery.com/jquery-1.11.3.min.js\"></script> <script> $(document).ready(function () {debugger$(\"#tituloPrueba\").css('color', 'red'); }); </script></head><body><h1 id=\"tituloPrueba\">Test</h1> </body></html>";
displayVideo.loadDataWithBaseURL("file:///android_asset/web/", html, "text/html", "UTF-8", null);
*As you can see in the loaded HTML, I am calling jquery from code.jquery.com
In the document ready i am testing jquery by adding css class to
<h1 id=\"tituloPrueba\">Test</h1>
when i execute the app nothing changes, i am guessing javascript or jquery is not working.
By the way: in the method
displayVideo.loadDataWithBaseURL("file:///android_asset/web/", html, "text/html", "UTF-8", null);
I have no idea what "file:///android_asset/web/"" is for , maybe the problem is there?