2

How to set two different size of text in one button on Android ?

I tried setTest(HTML.FromHTML ) but this method is deprecated.

Emil
  • 63
  • 6

2 Answers2

1

For Android : Spannable Text is the best option.

For Xamarin.Forms :

If you have already written Custom Renderer for Button then you can use the Spannable in Xamarin android same way like android does.

If you don't want to write render in Xamarin, then i you can add two different labels in a stack layout and handle the stack layout click via code behind or by writing Button command for stack layout.

jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44
1

Try the following:

        Button button = FindViewById<Button>(Resource.Id.myButton);

        SpannableStringBuilder spannable = new SpannableStringBuilder("Big Little");
        spannable.SetSpan(new AbsoluteSizeSpan(50), 0, 3, SpanTypes.ExclusiveInclusive);
        spannable.SetSpan(new AbsoluteSizeSpan(25), 4, 10, SpanTypes.ExclusiveInclusive);

        button.SetText(spannable, TextView.BufferType.Editable);

More info: https://developer.android.com/guide/topics/text/spans

jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44