同じ TextView 内の文字列のフォントサイズが異なる 質問する

同じ TextView 内の文字列のフォントサイズが異なる 質問する

textView内部に数値 (変数) と がありますstring。数値を より 1 サイズ大きくするにはどうすればよいでしょうかstring。コード:

TextView size = (TextView)convertView.findViewById(R.id.privarea_list_size);
if (ls.numProducts != null) {
    size.setText(ls.numProducts + " " + mContext.getString(R.string.products));
}

ls.numproducts のサイズをテキストの残りの部分と異なるサイズにしたいです。どうすればいいでしょうか?

ベストアンサー1

使うSpannable String

 String s= "Hello Everyone";
 SpannableString ss1=  new SpannableString(s);
 ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
 ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
 TextView tv= (TextView) findViewById(R.id.textview);
 tv.setText(ss1); 

スナップショット

ここに画像の説明を入力してください

スペースを使用して文字列を分割し、必要な文字列に span を追加できます。

 String s= "Hello Everyone";  
 String[] each = s.split(" ");

次にspanに適用しstring、同じものを に追加しますtextview

おすすめ記事