Why is the equivalent of Xamarin EditText.getText () returning a string?

I am a new Xamarin.Android developer. I recently read some Java code that used methods EditTextin a derived class. One of the methods of the derived class looked like this:

private void checkMatchingBracket(int paramInt)
{
    getText().removeSpan(this.openBracketSpan);
    getText().removeSpan(this.closeBracketSpan);
    ...
}

This confused me because I thought I getText()returned a String, since the property EditText.Textis Stringin this class the "equivalent of Xamarin." However, it is not; it seems to be getText()returning Editable, which looks like a mutable string type that offers additional functions, such as attaching "spans" to some areas of the text ( SpannableString?). I assume that the StringXamarin return was copied from the text of this Editable, so I cannot change the original Editableand use its API.

Am I right? Unable to access the original Editablehere because I'm using Xamarin?

edit: The specific thing I want to do is the colored areas of the text in EditText. I found this answer that uses spaces to achieve this:

TextView textView = (TextView)findViewById(R.id.mytextview01);
Spannable WordtoSpan = new SpannableString("partial colored text");        
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(WordtoSpan);

However, the Xamarin API EditText.Text.setonly accepts .NET String, which obviously has no idea about color or spans.

+4
source share
1 answer

You are looking for a property EditableText:

var editable = aTextView.EditableText;
editable?.RemoveSpan(aSpanObject);

Re: https://developer.xamarin.com/api/property/Android.Widget.TextView.EditableText/

Returns the text that the TextView displays as an editable object. If the text is not edited, null is returned.

+5
source

Source: https://habr.com/ru/post/1678952/


All Articles