3

I am loading html pages from assets and showing in application. HTML pages are showing but when I tried to change background color of button on "onclick" then background color is not getting change.

If i test pages with browser then it's working but when I load html pages in android using webview then it's not working.

onclick function getting called but somehow style property not getting applied. I tried following three ways.

1. $('#btnAC').css({'background-image', 'linear-gradient(180deg, black, red) !important'});  

2. document.getElementById("btnAC").style = "background-image: linear-gradient(180deg, black, red) !important;";  

3. $('#btnAC').css('background-image', 'linear-gradient(180deg, black, red) !important');

Java code :

WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http:///android_asset/Web/index.html"); 
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

1 Answers1

0

You could use WebView.loadDataWithBaseURL

  • htmlData = "" + htmlData; // lets assume we have /assets/style.css file webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);*
Maheswaran S
  • 525
  • 3
  • 12