TextView.BufferType:
- Normal: normal;
- Editable: characters can be appended;
- Spannable: use styles in the given character area;
The type of the text buffer that defines the characteristics of the text such as static, styleable, or editable. It could be used for changing the TextView in runtime.
TextView.BufferType.Editable
: Insert
TextView tv2 = FindViewById<TextView>(Resource.Id.textView2);
tv2.SetText("Hello", TextView.BufferType.Editable);
var s = tv2.EditableText;
s.Insert(1, " Hello");
OutPut:
TextView.BufferType.Spannable
: set the different color in a single Textview
TextView tv3 = FindViewById<TextView>(Resource.Id.textView3);
tv3.Text = "Hello World";
SpannableString wordtoSpan3 = new SpannableString(tv3.Text);
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Red), 0, 5, 0); // "Hello" is red
wordtoSpan3.SetSpan(new ForegroundColorSpan(Color.Blue), 7, 11, 0); // "orld" is blue
tv3.SetText(wordtoSpan3, TextView.BufferType.Spannable);
Output:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…