2017-05-22 11 views
1

SPAN_EXCLUSIVE_EXCLUSIVE 플래그를 사용하여 SpannableStringBuilder에 스팬을 설정하려고하는데 스팬을 설정하고있는 텍스트를 편집하는 중에 문제가 있습니다. android SPAN_EXCLUSIVE_EXCLUSIVE이 제대로 작동하지 않습니다.

Expected behaviour 1: Original text. 2: Text added before. 3: Text added after with space.

Unexpected Behaviour on adding text after styled text

나는 추가 된 텍스트 스타일, 내가 뭘 잘못 알고 싶어 싶지 않아.

EDIT 1 : 문제는 Moto X Play에서 발생하지만 Nexus 5X에서는 재생산되지 않습니다. 다른 장치에서 계속 테스트합니다.

답변

0

당신은 아마 당신이해야하는 방식이 아닌 텍스트를 추가 할 것입니다. 추가 텍스트를 추가하려면 .insert().append() SpanableStringBuilder 메서드를 사용하십시오.

난 그냥 결과입니다 당신이 여기에 달성하려고 노력 :

TextView hratkyTextView = (TextView) findViewById(R.id.spannableHratkyTextView); 

final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold 

// "Test text" part (in bold) 
SpannableStringBuilder builder = new SpannableStringBuilder("Test text"); 
builder.setSpan(bss, 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 

// Prepending "before" (non-bold) 
builder.insert(0, "before"); 

// Appending " after_with_space" to the end of the string 
builder.append(" after_with_space"); 

hratkyTextView.setText(builder); 

결과 : 이 코드를 통해 텍스트를 변경 Nexus 7 Emulator running MainActivity with this code

+0

아니, 그것은 입력에 의해 않던 글고 텍스트 변경했다 . – user3900924