Kevin F
Kevin F

Reputation: 169

Xamarin: TextView Clickable

I have problem with TextView Clickable. I need a TextLink that open some browser with a static link.

I'm dev on VS2012 with Xamarin Plugin. The problem is that the link not open the browser.

Mi file .axml (textView)

<TextView
    android:lines="2"
    android:id="@+id/textViewRegistrarse"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:textSize="10sp"
    android:textColor="@color/textlink"
    android:autoLink="web"
    android:text="Registrarse" />

and the file .cs:

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Login);

            var olvidoContraseña = FindViewById<TextView>(Resource.Id.textViewRegistrarse);

            olvidoContraseña.TextFormatted = Html.FromHtml(@"<a href=""https://www.google.cl/"">¿Olvidaste tu contraseña?</a>");
        }

Please Help.

Upvotes: 0

Views: 4254

Answers (2)

Fedin Maksim
Fedin Maksim

Reputation: 21

Try this

olvidoContraseña.Click += OpenLink;
private void OpenLink(object sender, EventArgs e){
var intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
StartActivity(intent);
}

Upvotes: 1

Martijn00
Martijn00

Reputation: 3559

You can do that with this code:

intent.button.Click += delegate {
       var uri = Android.Net.Uri.Parse ("http://www.google.com");
       var intent = new Intent (Intent.ActionView, uri); 
       StartActivity (intent);     
};

For a full example see: http://developer.xamarin.com/recipes/android/fundamentals/intent/open_a_webpage_in_the_browser_application/

Upvotes: 1

Related Questions