0

Is it possible to change text color in Jsoup ?

Here is my code:

String uColor;
titleColor = doc.select("u").text();

How can I change the text color of titleColor? Is it possible ?

public class Odpowiedzi extends AsyncTask<String, String, String>{

    int swiatInt;

    String swiat;
    String url = "http://gra96procent.blogspot.com/";
    String odp;
    String zlySwiat = "Nie ma takiego świata w tej grze ! ";
    String titleColor;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        swiat = swiatEdt.getText().toString();
        swiatInt = Integer.parseInt(swiat);

        if (swiatInt >= 1 && swiatInt <= 60){
            url = url + "2015/11/swiat-" + swiat + ".html";
        }

        if (swiatInt >= 61 && swiatInt <= 62){
            url = url + "2015/12/swiat-" + swiat + ".html";
        }

        if (swiatInt >= 63 && swiatInt <= 80){
            url = url + "2016/02/swiat-" + swiat + ".html";
        }

        if (swiatInt >= 80 && swiatInt <= 110){
            url = url + "2016/04/swiat-" + swiat + ".html";
        }

        if (swiatInt >= 111 && swiatInt <= 120){
            url = url + "2016/09/swiat-" + swiat + ".html";
        }

        if (odpowiedzi.getText().toString() == ""){
            odpowiedzi.setText("Podaj świat, aby uzyskać odpowiedzi!");
        }


    }

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

        try{
            Document doc = Jsoup.connect(url).get();

            doc.select("br").append("\\n");
            doc.select("p").prepend("\\n\\n");

            doc.select("b").append("\n");
            doc.select("b").prepend("\n");

            doc.select("ul").append("\\n\\n");

            doc.select("h3").append("\\n\\n");

            doc.select("li").append("\\n");
            doc.select("li").prepend("\n");

            doc.select("u").append("\\n");
            titleColor = doc.select("u").text();

            odp = doc.select("div#Blog1").text().replace("\\n", "\n").
                    replaceAll("Nowszy post Starszy post Strona główna", "");

        }

        catch (IOException e){
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        odpowiedzi.setText(odp);

        if (swiatInt > 120){
            odpowiedzi.setText(zlySwiat);
        }

    }
jestembotem
  • 85
  • 1
  • 11

1 Answers1

0

The best way to get HTML style attribute is from style CSS.

    Document document = Jsoup.parse(html);
    String style = document.select("style").first().data();

You can then use a CSS parser to fetch the details you are interested in.

http://www.w3.org/Style/CSS/SAC

http://cssparser.sourceforge.net

https://github.com/corgrath/osbcp-css-parser#readme

Afterwards you can use the color to set the text

text.setTextColor(Color.parseColor("#FFFFFF"));
Gufran Khurshid
  • 888
  • 2
  • 9
  • 28