From the android docs, there are 3 types of buffer for TextView
, EDITABLE
, NORMAL
and SPANNABLE
. What is the difference between each of them and what are some of their common use cases?
TextView. BufferType will be used for changing the TextView in runtime like insert, setting the different color in a single TextView, style etc. EDITABLE -> only return Spannable and Editable.
android.widget.TextView.BufferType. Type of the text buffer that defines the characteristics of the text such as static, styleable, or editable.
TextView.BufferType
will be used for changing the TextView
in runtime like insert, setting the different color in a single TextView, style etc.
EDITABLE
-> only return Spannable and Editable.
NORMAL
->only return any CharSequence.
SPANNABLE
-> only return Spannable.
Here is TextView.BufferType.EDITABLE
uses.
yourTextView.setText("is a textView of Editable BufferType",TextView.BufferType.EDITABLE);
/* here i insert the textView value in a runtime*/
Editable editable = youTextView.getEditableText();
editable.insert(0,"This "); //0 is the index value where the "TEXT" will be placed
Ouput:
This is a textView of Editable BufferType
Here is TextView.BufferType.SPANNABLE
uses and This is also written by TextView.BufferType.EDITABLE
(because editable written spannable or editable) by changing the arguments
yourTextView.setText("textView of Spannable BufferType",TextView.BufferType.SPANNABLE);
/* here i change the color in a textview*/
Spannable span = (Spannable)yourTextView.getText();
span.setSpan(new ForegroundColorSpan(0xff0000ff),11,"textView of Spannable BufferType".length(),Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
Output:
textView of `Spannable BufferType`(Spannable BufferType are in blue color)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With