You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Android HtmlView Does not accept size or font face styling #4746
Html view in android does not accept styling or font-family. IOS this works.
Here is a sample code that does not style correctly <HtmlView html="<span><b><font size='10' color='blue' face='lato'>{{item.text}} </font></b></span>" </HtmlView>
changed the title [-]Android View Does not accept size or font face styling[/-][+]Android HtmlView Does not accept size or font face styling[/+]on Aug 24, 2017
Hi @anuragd7,
YOu have missed adding the closing bracket for the HTML tag, which will lead to this behavior.
If you add it the problem should be resolved. For Example:
The reasons for this is the difference how iOS and Android are parsing the HTML to the corresponding "rich text" properties.
In our project we decided to create an angular component which deals with the different implementations so we don't have to deal with it on each location where we use the HTMLView.
The idea for the HtmlView module is to be used for the most basic scenario, like providing HTML string and supports only several styleing properties like color.
Regarding that, We have a better component called WebView, which provides better control over your HTML content, which you need to display. Apart from providing URL, you can also pass HTML string for your WebView just as you would do with HTML View. The property that needs to handle the HTML string is called src.
For example:
<WebView src="<span><b><font size='24' color='blue' face='lato'>blue text</font> and non-blue text</b></span>"></WebView>
With the WebView also the font properties will be applied as expected.
Hi @corne-de-bruin ,
Many thanks for the suggestion - will definitely try it out!
Hi @tsonevn
I am using the Htmlview in a listview. I had tried the Webview some time back and it seemed to make the app sluggish. Thanks for the example though.
Hi @madmas,
The WebView is better in the cases when you need to display HTML code while respecting all CSS properties added on it.
In the scenario when you will just display a text, you can use the HTMLView, which will improve the performance of the app. However, the style of the text will be restricted.
@tsonevn what do the cssClasses, css properties in the HtmlView class do? Are these properties settable, and if so, can they be used to customize the view's css?
Also tried using the HtmlView color property (color="#ff0000" for e.g.) but it does nothing to the actual html content..
Hi @suparnavg,
The HtmlView view is designed to display pure HTML code and some of the CSS properties might not be applied to its content. If you want to display rich CSS HTML, you can use the WebView component.
Activity
[-]Android View Does not accept size or font face styling[/-][+]Android HtmlView Does not accept size or font face styling[/+]tsonevn commentedon Aug 24, 2017
Hi @anuragd7,
YOu have missed adding the closing bracket for the HTML tag, which will lead to this behavior.
If you add it the problem should be resolved. For Example:
If the problem still persists, please send us a sample project, which could be debugged locally.
corne-de-bruin commentedon Aug 25, 2017
Hi @anuragd7,
We've faced the same issue in our project with setting the font family.
To set the font for Android we used the following code:
The reasons for this is the difference how iOS and Android are parsing the HTML to the corresponding "rich text" properties.
In our project we decided to create an angular component which deals with the different implementations so we don't have to deal with it on each location where we use the HTMLView.
tsonevn commentedon Aug 25, 2017
Hi @corne-de-bruin @anuragd7,
The idea for the HtmlView module is to be used for the most basic scenario, like providing HTML string and supports only several styleing properties like color.
Regarding that, We have a better component called WebView, which provides better control over your HTML content, which you need to display. Apart from providing URL, you can also pass HTML string for your WebView just as you would do with HTML View. The property that needs to handle the HTML string is called src.
For example:
With the WebView also the font properties will be applied as expected.
anuragd7 commentedon Aug 25, 2017
Hi @corne-de-bruin ,
Many thanks for the suggestion - will definitely try it out!
Hi @tsonevn
I am using the Htmlview in a listview. I had tried the Webview some time back and it seemed to make the app sluggish. Thanks for the example though.
madmas commentedon Mar 22, 2018
@tsonevn if WebView is the better component, why does the docs state "Use this component instead of a WebView when you want to show static HTML content." ?
https://docs.nativescript.org/angular/code-samples/ui/htmlview
tsonevn commentedon Mar 23, 2018
Hi @madmas,
The WebView is better in the cases when you need to display HTML code while respecting all CSS properties added on it.
In the scenario when you will just display a text, you can use the HTMLView, which will improve the performance of the app. However, the style of the text will be restricted.
captainhaddock29 commentedon Apr 26, 2018
Hi @corne-de-bruin !
Could you share your angular component please ?
corne-de-bruin commentedon Apr 26, 2018
Hi @captainhaddock29
HTML:
This is our Angular component:
suparnavg commentedon Sep 14, 2018
@tsonevn what do the cssClasses, css properties in the HtmlView class do? Are these properties settable, and if so, can they be used to customize the view's css?
Also tried using the HtmlView color property (color="#ff0000" for e.g.) but it does nothing to the actual html content..
tsonevn commentedon Mar 19, 2019
Hi @suparnavg,
The HtmlView view is designed to display pure HTML code and some of the CSS properties might not be applied to its content. If you want to display rich CSS HTML, you can use the WebView component.
rahadur commentedon Mar 23, 2019
This is how i create a HtmlView custom component.
Angular Component 💥💥💥
lock commentedon Mar 22, 2020
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.