How do you change text to bold in Android?

后端 未结 19 756
走了就别回头了
走了就别回头了 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:01

    In XML

    android:textStyle="bold" //only bold
    android:textStyle="italic" //only italic
    android:textStyle="bold|italic" //bold & italic
    

    You can only use specific fonts sans, serif & monospace via xml, Java code can use custom fonts

    android:typeface="monospace" // or sans or serif
    

    Programmatically (Java code)

    TextView textView = (TextView) findViewById(R.id.TextView1);
    
    textView.setTypeface(Typeface.SANS_SERIF); //only font style
    textView.setTypeface(null,Typeface.BOLD); //only text style(only bold)
    textView.setTypeface(null,Typeface.BOLD_ITALIC); //only text style(bold & italic)
    textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD); 
                                             //font style & text style(only bold)
    textView.setTypeface(Typeface.SANS_SERIF,Typeface.BOLD_ITALIC);
                                             //font style & text style(bold & italic)
    

提交回复
热议问题