2016-10-31 25 views
3

android docsから、TextView,EDITABLE,NORMALおよびSPANNABLEの3種類のバッファがあります。それぞれの違いは何ですか?共通のユースケースは何ですか? >のみを返すSpannableと編集可能 -TextView BufferType

答えて

2

TextView.BufferType等、単一のTextViewで別の色、スタイル

EDITABLEを設定し、挿入などのruntimeTextViewを変更するために使用されます。

NORMAL - > CharSequenceのみを返します。

SPANNABLE - >返されるのはSpannableのみです。

ここにはTextView.BufferType.EDITABLEが使用されています。

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 

出力リレー:

ここ
This is a textView of Editable BufferType 

TextView.BufferType.SPANNABLE用途で、これはまた、引数に変更することによって、(編集可能なので、spannableまたは編集可能な書かれた)TextView.BufferType.EDITABLEによって書かれ

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); 

出力:

textView of `Spannable BufferType`(Spannable BufferType are in blue color)