HtmlSpanner with css
I have found an library called HtmlSpanner that should help me with adding a html string with css to a TextView.
but i cant find any documentation on it except
(new HtmlSpanner()).fromHtml()
but nothing on how to include a css file to it or how i can create an TagManager on handeling the css
can anyone help me?
Out of the box HtmlSpanner does parse blocks, and is able to apply the CSS styles in those blocks to the text.
The code for that is in the StyleNodeHandler handler class.
Now the good news is that it's pretty easy to add new TagNodeHandler classes, and in your case all you'd need is to add one that
does the following:
List item
Read the "href" property from the CSS link
Retrieve the URL that the href points to and read it into a String
Parse the String into a CSS rule
Register that CSS rule
Steps 3 and 4 are already in the StyleNodeHandler class (in the parseCSSFromText method), so you'd only need to implement steps 1 and 2.
Here's a quick Gist of what you'd need to add:
link
Related
The question might seem incomprehensible just from the title alone so let me elaborate on what I mean. From what little I've dabbled in HTML and JavaScript, you could add HTML lines to the HTML file from using a Javascript function in the script.js file and it would add those HTML lines you've written into the function to the HTML file on execution and it would work as if you've written it in the HTML file to begin with. That was my understanding of how it worked, at least, if I'm wrong on my assessment feel free to correct me on that matter.
Anyway, I'm wondering if we could do a similar thing in Android Studio where we can use a Kotlin function to add an XML line/attribute/command like 'app:srcCompat="#drawable/whatever"' to an XML file.
Of course the question doesn't come from a mere sense of wonder. I currently have an application with a fragment that's supposed to get some football teams from the Room database and display them in CardViews using RecyclerView. In those cards, the team's name and their logo should be displayed. I don't have logos as image files in the Room database itself, however there is a column that stores the names of the drawable files in which the team logos are stored. (For example: Team A's logo is stored in the drawable's as 'teama.png' and it has 'teama' stored in a column.)
In the Adapter class of the RecyclerView, I want to use the bind() function to put the name and the logo on the cards. What I'm expecting to do (related to my question overall) is using a function that can take a string parameter ("app:srcCompat="#drawable/teama"") and puts it to the XML file of my team item. Is this possible? I'm open to other solutions as well and can post code if requested.
Thank you for your answer beforehand.
Is there a way to add XML code to an XML file from a Kotlin code?
Yes, but not in the context of what you are asking.
What I'm expecting to do (related to my question overall) is using a function that can take a string parameter ("app:srcCompat="#drawable/teama"") and puts it to the XML file of my team item. Is this possible?
No. You cannot modify the content of a resource XML file at runtime.
From what little I've dabbled in HTML and JavaScript, you could add HTML lines to the HTML file from using a Javascript function in the script.js file and it would add those HTML lines you've written into the function to the HTML file on execution and it would work as if you've written it in the HTML file to begin with.
JavaScript, run in the browser, does not modify the HTML file on the server. It modifies the DOM: the parsed representation of the HTML that is used by the browser to render a UI on the screen.
Similarly, in Android, you will need to update the View objects โ created from parsing that resource XML file โ to reflect your desired name and logo. This approach is covered in books and courses on Android app development. FWIW, here is a free book of mine on the subject.
Till now this technology is not available and if it is available it's not that famous and in use
I have a custom tag called some data that i wish to extract. However it seems to me that by doing the following code in android, it automatically remove my </link> and replace it onto the first tag.
Document document = Jsoup.parse("<html><head></head><body><link>test</link></body></html>");
Log.e(Config.log_id, document.html());
The following code will result in <html><head></head><body><link />test</body></html>
once i did a .html. Any solution here?
seems to be that the keyword link is used. I have to replace to before parsing and it worked.
I try to parse the source file of a website called dgtle.com
In order to get the top news, I coded as :
Document doc = Jsoup.connect("http://www.dgtle.com").get();
Elements blocks = doc.getElementsByClass("listcs1");
I got nothing but NullPointerExecption while doing this. But the Div with the class ofใ"listcs1" really exists. This troubles me and I'm wondering whether anybody can help me deal with this.
Use a doc.select instead of getElementsByClass..
ex.
Elements blocks = doc.select("div.listcs1");
this will get all divs with the class of "listcs1"
Jsoup lists all of the selection combinations here: http://jsoup.org/cookbook/extracting-data/selector-syntax
The title maybe a little confusing so I shall explain a lot more details here. First off, I have an URL link that uses HTTPS secured site. I already managed a successful attempt to use a WebView to connect to the site, using loadDataWithBaseURL method.
The URL link does not end with .xml, so I am stuck with this problem. What are the procedures to do in order I can use the xml data on an URL link that does not ends with .xml?
EDIT:
<MGMT>
<NET>
<HEAD>
<ClientID>99999999</ClientID>
<ServerID>WEB_01</ServerID>
<Rsp>00</Rsp>
<Auth></Auth>
</HEAD>
<STAT>
<IP>192.168.5.158</IP>
<Status>OK, Success!</Status>
</NET>
</MGMT>
I do have XML parsing knowledge. But that is if the url link returns a XML data or I have an XML file. This is NOT THE ACTUAL LINK but it is similar, I changed a few values in it.
https://192.168.0.254/?ClientID=999999&Cert=0f7a248e3b017effec2b36cf53912b0f&IP=192.168.5.128
Ok. As i come to know about your question, you have to gain some knowledge about xml parsing which convert the fetched XML data in to specific variables.
Here in below examples, the project get the Http responce from the server which is in the formate of the xml file. (Which URL not having .XML extention). And that data are stored in to specific variable.
You have to fetch various data based on the tab as per your xml structure. as like "MGMT", "NET" . . .etc etc. . .
See this: Example 1
Also see this: Exapmple 2
Hope you got the Logic to do it.
What would the best approach to :
get html codes by calling url and displaying it in some views
if i would be editing the values against title tag, it must be automatically updated in the url link?
How to do this?
Check out the JSoup cookbook.
http://jsoup.org/cookbook/
This has a lot of good information in it and should be able to answer most of your questions.
You are probably looking for something along the lines of this: http://jsoup.org/cookbook/input/parse-body-fragment