android: string format specify bold

后端 未结 7 616
半阙折子戏
半阙折子戏 2021-01-05 05:05

I have a string defined in string.xml like

Title: %1$s 

which is formatted us

相关标签:
7条回答
  • 2021-01-05 05:54
    Typeface tfaerial=Typeface.createFromAsset(getAssets(),"fonts/aerial.ttf");
    Typeface tfTradeGothicLight=Typeface.createFromAsset(getAssets(), "fonts/TradeGothic-Light.OTF");
    
    String strt_title_desc=this.getResources().getString(R.string.eventtitle);
    

    int upto=strt_title_desc.indexOf(":"); //of you can specify 5

     if (strt_title_desc!=null)
        {
            aboutAuthTV.setTextColor(Color.BLACK);
            aboutAuthTV.setLineSpacing(1.2f, 1.5f);
            aboutAuthTV.setTextSize(23);
        SpannableString SS = new SpannableString(strt_title_desc);
        SS. setSpan ( new StyleSpan(tfTradeGothicLight.getStyle()), 0, upto,Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        SS. setSpan ( new StyleSpan(tfaerial.getStyle()), upto, strt_dialog_desc.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        yourtextView.setText(SS);
    }
    

    // this for changing the font size, style and colors

    String str="<font size =\"20\"><B>Bold</B> <br/> Then Normal Text<br/>
                             <i>Then Italic</i> </font>" +
                           "<br/> <font color=\"green\" >this is simple sentence </font>" +
                           "<br/><br/><br/><br/><a>this is simple sentence</a>";
          Spanned strHtml= Html.fromHtml(str);
    
           TextView tv = (TextView)findViewById(R.id.textView);
           tv.setText(strHtml);
    
    0 讨论(0)
提交回复
热议问题