Search code examples
javaandroidtextviewandroid-textattributes

Android textview text with two different sizes


Im trying to set html text with different text sizes in one textview but nothing.

I'm trying like this:

textViewNextTime.setText(Html.fromHtml("<h2>4</h2><p>38</p>"));

and also I've tried using and tags but without success. Can anyone help me to create a textView with text like this(without the circle ofcourse):

enter image description here

Edit: In example the 4 should be like 140sp in size, and the :38 should be something like 70sp in size


Solution

  • If you don't need to use html you can try something like this:

    String s= "4:38";
    SpannableString ss1=  new SpannableString(s);
    ss1.setSpan(new RelativeSizeSpan(2f), 0, 1, 0); // set size
    TextView tv= (TextView) findViewById(R.id.textview);
    tv.setText(ss1);