Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of string created in resources Xamarin.android

I am developing an android application in Xamarin studios and want to make a text of a button underlined. I created a string in strings.xml like the following

 <string name="Advanced_Search"><u>Advanced Search</u></string>

I was succesfully able to reference this string in the xml file for the desginer, however I want to access it in code to set it as a button's text. I tried the following but it doesn't work:

advancedSearchButton.Text = Resource.String.Advanced_Search.ToString();

When i try to reference the string like that i get an integer value for the string, but I actually want the text that the string holds. How can I access the string like that in Xamarin using c#?

like image 928
Harshil.Chokshi Avatar asked Mar 11 '23 01:03

Harshil.Chokshi


1 Answers

You need to use Resources.GetString:

advancedSearchButton.Text = Resources.GetString(Resource.String.Advanced_Search);

This is assuming the code is contained within an Activity, otherwise you need to have a reference to an Android Context.

like image 166
Tom Gilder Avatar answered Apr 05 '23 23:04

Tom Gilder