I have Xamarin.Android project
and use MVVMCross
. I need to add some underlining text in my .axml
layout.
I found some ways to do it but its don't work for me.
I have this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/toolbar" />
<TextView
android:id="@+id/TextView01"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_below="@+id/toolbar"
local:MvxBind="Text Strings[Text01]" />
<TextView
android:id="@+id/textLink"
android:textSize="13sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:textColor="#1565C0"
android:layout_below="@id/TextView01"
local:MvxBind="Text Strings[textLink]; Click MyCommand" />
</RelativeLayout>
The string.
<string name="your_string"><u>Underlined text</u></string>
I can't use this way because I use two languages and I have the folder Locales
with two .txt
files. So the project doesn't take strings from strings.xml
Paint.
TextView MyLink = FindViewById<TextView>(Resource.Id.MyLink);
MyLink.PaintFlags = (MyLink.PaintFlags | Android.Graphics.PaintFlags.UnderlineText);
FromHtml.
txtView.setText(Html.fromHtml("<u>underlined</u> text"));
Doesn't work for me, besides I see the green underline and comment that this decision is deprecated.
How can I mark my TextView
as underlined?
Option 2 looks like Java instead of xamarin c#, try:
txtView.PaintFlags = (txtView.PaintFlags | Android.Graphics.PaintFlags.UnderlineText);
And use the correct Id.