2015-11-05 28 views
0

我試圖從我的SpannableString中刪除樣式,但不幸的是沒有工作,我的目標是刪除樣式,當點擊文本。如何從SpannableString中刪除範圍樣式

SpannableString content = new SpannableString("Test Text"); 
content.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, content.length(), 0); 
... 

的onClick操作:

content.removeSpan(new StyleSpan(Typeface.BOLD_ITALIC)) // not working 

在此先感謝

回答

2

兩個styleSpan你新的是不一樣的物體。您可以使用非匿名對象來指向它。更改代碼這樣的:

StyleSpan styleSpan = new StyleSpan(Typeface.BOLD_ITALIC); content.setSpan(styleSpan , 0, content.length(), 0);

的onClick操作:

content.removeSpan(styleSpan); 
textView.setText(content);// to redraw the TextView