I want to set the title of the TabLayout with two different text sizes. Like the given image below. Or the other way around to achieve this!
I have tried with SpannableString like give below. This snippet is in the for loop till 5!
SpannableString mSpannableString= new SpannableString(s);
mSpannableString.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
mSpannableString.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
mTabLayout.getTabAt(i).setText(mSpannableString);
But as mentioned by CommonaSware setText() is not taking the rich content!
setText()
on aTabLayout.Tab
takes aCharSequence
. If rich formatting via aSpannableString
does not work, that feels like a bug inTabLayout
. Please edit your question and provide a minimal reproducible example demonstrating how you attempted to set the text of the tabs. – EncapsulateTextAppearance
style that's set by default on the tabs'TextView
s that's causing that. If you don't want to use a customView
for the tabs, there's a way to set theTextAppearance
on them that won't strip the spannable stuff. – LavernelaverockTextAppearance
either I can set the Large font or Small font size. Mine need to have both it's like title & sub-title. – MartinsonTextAppearance
style that causes the spannable info to be lost. If you use your own style with that set tofalse
, yourSpannableString
will work as intended. – Lavernelaverock