Creating a custom button with two lines of text, each with a different font

前端 未结 1 1179
情话喂你
情话喂你 2021-02-03 16:11

I\'m a little stuck here and could really use some help. It seems to me that it should be pretty easy to add two separate lines of text to a button. But it just isn\'t. There

相关标签:
1条回答
  • 2021-02-03 16:38
    String s1;
    String s2;
    int n = s1.length();
    int m = s2.length;
    
    Typeface customFont = Typeface.createFromAsset(getAssets(),"fonts/zooper.ttf");
    Spannable span = new SpannableString(s1 + "\n" +  s2);
    //Big font till you find `\n`
    span.setSpan(new CustomTypefaceSpan("", customFont), 0, n, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    //Small font from `\n` to the end
    span.setSpan(new RelativeSizeSpan(0.8f), n, (n+m+1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    yourButton.setText(span);
    

    enter image description here

    0 讨论(0)
提交回复
热议问题