I currently have a android:TextView which is bound to a string which may or may not contain HTML.
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:padding="10dp"
style="@style/ListItemText"
local:MvxBind="Text Answer" />
Somehow I need to be able to display this text with the html rendered. So I thought I would switch the TextView to a WebView and bind the same string to the WebView. I'm fairly new to Android dev, so I'm not sure if this can even be done or if there is another way I should be approaching this.
For small amounts of HTML text, you can use the TextFormatted property of a TextView - usually with a ValueConverter which will perform the HTML parsing (using Html.FromHtml(input)
)
public class FromHtmlValueConverter : MvxValueConverter<string>
{
protected override object Convert(string value, Type targetType, object parameter, CultureInfo culture)
{
return Html.FromHtml(value);
}
}
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:padding="10dp"
style="@style/ListItemText"
local:MvxBind="TextFormatted FromHtml(Answer)" />
For rendering a full WebView, then you'll need to add a custom binding - or inherit and provide a custom property - in order to call LoadData when the VM changes. This is similar to the inheritance technique used for UIWebView in Dynamic Binding UIWebView in MVVMCross
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With