TextView個別文字フォントの色フォーマットの設定
2489 ワード
方法一Htmlで文字設定をフォーマットする TextView htmlFormateTextView = (TextView)findViewById(R.id.txtTextView);
String source = " , <u> </u>、<i> </i>、<font color='red'> </font> ";
htmlFormateTextView.setText(Html.fromHtml(source));
方法2 Spannableによる設定 EditText et = (EditText) findViewById(R.id.txtTextView);
Spannable sp = (Spannable) et.getText();
sp.setSpan(new BackgroundColorSpan(Color.RED), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 6, 11, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
拡張知識Spannable
TextView htmlFormateTextView = (TextView)findViewById(R.id.txtTextView);
String source = " , <u> </u>、<i> </i>、<font color='red'> </font> ";
htmlFormateTextView.setText(Html.fromHtml(source));
EditText et = (EditText) findViewById(R.id.txtTextView);
Spannable sp = (Spannable) et.getText();
sp.setSpan(new BackgroundColorSpan(Color.RED), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 6, 11, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);