Skip to content

Instantly share code, notes, and snippets.

@7fe
Created March 10, 2017 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7fe/3b601977fcfc430171bdef6ac4758b15 to your computer and use it in GitHub Desktop.
Save 7fe/3b601977fcfc430171bdef6ac4758b15 to your computer and use it in GitHub Desktop.
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView w;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
w = (WebView) findViewById(R.id.activity_main_webview);
w.getSettings().setJavaScriptEnabled(true);
w.getSettings().setBuiltInZoomControls(true);
w.getSettings().setDisplayZoomControls(false);
/*w.setClickable(true);
w.getSettings().setDomStorageEnabled(true);
w.getSettings().setSaveFormData(true);
w.getSettings().setAllowContentAccess(true);
w.getSettings().setAllowFileAccess(true);
w.getSettings().setAllowFileAccessFromFileURLs(true);
w.getSettings().setAllowUniversalAccessFromFileURLs(true);
w.getSettings().setSupportZoom(true);
w.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);*/
w.setWebChromeClient(new WebChromeClient());
w.loadUrl("http://dus.tn/music.html");
w.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView w, String url) {
String s = "javascript:"
+ "(function () {"
+ " try{document.body.style.color='blue';del();}catch(e){}"
+ "})();";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
w.evaluateJavascript(s, null);
else w.loadUrl(s);
}
});
}
@Override
public void onBackPressed() {
if(w.canGoBack())w.goBack();
else super.onBackPressed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment