1

I am trying to improve the look to a certain Website by altering the HTML code. I want to change some stuff like the color of a specific text, make a picture a little bit bigger, and things of this nature.

Things I know how to do:

1: Get the HTML code using Jsoup

2: Display the code into a WebView

Things I want to know how to do:

1: Be able to modfiy the look of a Website

2: Do it quickly

For demonstration purposes, let me use this website as an example. If you follow this link you will get a list of users.

stackoverflow.com/users

How can I change the color of the user names to dark red?

https://i.stack.imgur.com/uysWi.png

This is my current code based on the things I know how to do.

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;

public class MainActivity extends Activity {
    WebView web;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new MyTask().execute();

         }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


    private class MyTask extends AsyncTask<Void, Void, String> {

          @Override
          protected String doInBackground(Void... params) {

            Document doc;

            String htmlcode = "";

            try {
                doc = Jsoup.connect("http://stackoverflow.com/users").get();

                 htmlcode = doc.html();


            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


            return htmlcode;   
          } 


          @Override
          protected void onPostExecute(String result) {        
              web = (WebView) findViewById(R.id.webView1);
              web.loadData(result,  "text/html", null);
          }
        }

}

Please show me how this works, I appreciate your time.

Ammar
  • 1,203
  • 5
  • 27
  • 64

1 Answers1

0

Its a dynamic data which coming from the server of stackoverflow. You can not change the color of anything you like. But if you are talking about any static html page then yes you can able to do anything.

You have to open that htmp page in to viewSourceMode and there you have to find that tag where you want to change the color and replace your color. Then you can load it in to the android WebView to see the changes.

You can also change the color dynamically while loading of the WebView. But only with the static html page.

Hope you got my point.

feel free to comment.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • I think there is a way to do it using a custom CSS. I think I can remove the website CSS and use a custom one. I am still not sure about how it works. But there must be a way out there! – Ammar Jan 29 '13 at 14:07
  • if you want to add custom css then you must have to give the path of your CSS right. But in dynamic html page there is path given for there own CSS file. How you can change it dynamically at run time to your CSS? As i think its only possible on static html page not for dynamic others html page. – Shreyash Mahajan Jan 30 '13 at 03:51
  • you can refer this : http://stackoverflow.com/questions/4950729/rendering-html-in-a-webview-with-custom-css – Shreyash Mahajan Jan 30 '13 at 03:53