How do you change text to bold in Android?

后端 未结 19 618
走了就别回头了
走了就别回头了 2020-12-02 04:21

How do you change text/font settings in an Android TextView?

For example, how do you make the text bold

相关标签:
19条回答
  • 2020-12-02 05:05

    To do this in the layout.xml file:

    android:textStyle
    

    Examples:

    android:textStyle="bold|italic"
    

    Programmatically the method is:

    setTypeface(Typeface tf)
    

    Sets the typeface and style in which the text should be displayed. Note that not all Typeface families actually have bold and italic variants, so you may need to use setTypeface(Typeface, int) to get the appearance that you actually want.

    0 讨论(0)
  • 2020-12-02 05:06
    editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
    etitText.setTypeface(et.getTypeface(), Typeface.BOLD);
    

    will set both typface as well as style to Bold.

    0 讨论(0)
  • 2020-12-02 05:12

    Assuming you are a new starter on Android Studio, Simply you can get it done in design view XML by using

    android:textStyle="bold"          //to make text bold
    android:textStyle="italic"        //to make text italic
    android:textStyle="bold|italic"   //to make text bold & italic
    
    0 讨论(0)
  • 2020-12-02 05:14

    in file .xml, set

    android:textStyle="bold" 
    

    will set text type is bold.

    0 讨论(0)
  • 2020-12-02 05:15

    For case where you are using custom fonts, but do not have bold typeface for the font you can use:

    myTextView.setText(Html.fromHtml("<b>" + myText + "</b>");
    
    0 讨论(0)
  • 2020-12-02 05:16

    Simply you can do the following:

    Set the attribute in XML

      android:textStyle="bold"
    

    Programatically the method is:

    TextView Tv = (TextView) findViewById(R.id.TextView);
    
    Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
    
    Tv.setTypeface(boldTypeface);
    

    Hope this helps you thank you.

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