在TextView中可以有多個樣式嗎?是否可以為TextView中的不同文本設置多個樣式?例如,我將文本設置為:tv.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);對于每個文本元素是否可能有不同的樣式?例如,行1粗體,字1斜體等。開發商指南常見任務及其在Android中的實現方法包括選擇、高亮顯示或設計文本的部分:// Get our EditText object.EditText vw = (EditText)findViewById(R.id.text);// Set the EditText's text.vw.setText("Italic, highlighted, bold.");// If this were just a TextView, we could do:// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);// to force it to use Spannable storage so styles can be attached.// Or we could specify that in the XML.// Get the EditText's internal text storageSpannable str = vw.getText();// Create our span sections, and assign a format to each.str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);但在文本中使用顯式位置號。有更干凈的方法嗎?
在TextView中可以有多個樣式嗎?
慕的地6264312
2019-06-05 16:11:26