Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6675903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:55:09+00:00 2026-05-26T03:55:09+00:00

In android I’m using WebView to display a part of a webpage which I

  • 0

In android I’m using WebView to display a part of a webpage which I fetched from the internet using HttpClient from Apache. To only have the part I want from the html, I use Jsoup.

String htmlString = EntityUtils.toString(entity4); // full html as a string                                 
Document htmlDoc = Jsoup.parse(htmlString); // .. as a Jsoup Document
Elements tables = htmlDoc.getElementsByTag("table"); //important part

Now I can just load tables.toString() in the WebView and it displays. Now I want to link a CSS file which I store inside my assets folder with this page. I know I can have something like

<LINK href="styles/file.css" type="text/css" rel="stylesheet">   

In my html, but how do I link it so that it uses the one I’ve stored locally?

—EDIT—
I’ve now changed to this:

StringBuilder sb = new StringBuilder();
    sb.append("<HTML><HEAD><LINK href=\"file:///android_asset/htmlstyles_default.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>");
    sb.append(tables.toString());
    sb.append("</body></HTML>");
    return sb.toString();

Somehow I do not get the styles applied to the page. Is it the location path I used that is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:55:10+00:00Added an answer on May 26, 2026 at 3:55 am

    Seva Alekseyev is right, you should store CSS files in assets folder, but referring by file:///android_asset/filename.css URL doesn’t working for me.

    There is another solution: put CSS in assets folder, do your manipulation with HTML, but refer to CSS by relative path, and load HTML to WebView by loadDataWithBaseURL() method:

    webView.loadDataWithBaseURL("file:///android_asset/", htmlString, "text/html", "utf-8", null);
    

    E.g. you have styles.css file, put it to assets folder, create HTML and load it:

    StringBuilder sb = new StringBuilder();
    sb.append("<HTML><HEAD><LINK href=\"styles.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>");
    sb.append(tables.toString());
    sb.append("</body></HTML>");
    webView.loadDataWithBaseURL("file:///android_asset/", sb.toString(), "text/html", "utf-8", null);
    

    P.S. I’ve come to this solution thanks to Peter Knego’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Android 4.0 phones only have virtual buttons, which actually go invisible when playing youtube/video
Android allows content of a URL to be displayed within an application using WebView
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
Android: i am using gps check box in my application, which user check this
[Android Newbie alert] I need to capture the contents of a WebView in a
Android Market app purchases have a 15-min grace period when a customer can cancel
Android 2.2 release notes have just been released. ActivityManager.restartPackage method has been deprecated and
Android supports a limited version of apache's http client(v4). typically if I want to
Android: I am using following code to insert image into album According to description
Android beginner, Can anybody guide me on this ? I do have the distance,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.