3

I have a button in that i want two different text size to be displayed. i have declared that text into string.xml and i have set text in java code by btnSin.setText(getResources().getString(R.string.lblasin) + "\n" + getResources().getString(R.string.lblSin)); so what is the way to do so.

shivani patel
  • 225
  • 1
  • 8
  • 22

2 Answers2

5
SpannableStringBuilder spanSin = new SpannableStringBuilder();
    SpannableString itemasin = new SpannableString(getResources().getString(R.string.lblasin)+"\n");
    itemasin.setSpan(new AbsoluteSizeSpan(9, true), 0,itemasin.length(),0);
    itemasin.setSpan(new ForegroundColorSpan(Color.parseColor("#EA7C07")), 0, itemasin.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanSin.append(itemasin);

    SpannableString itemsin = new SpannableString(getResources().getString(R.string.lblSin));
    itemsin.setSpan(new AbsoluteSizeSpan(12, true), 0,itemsin.length(),0);
    spanSin.append(itemsin);
    btnSin.setText(spanSin,BufferType.SPANNABLE);
shivani patel
  • 225
  • 1
  • 8
  • 22
2

Wrap the two strings in AbsoluteSizeSpan objects

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127