font.italic java code example

Example: how to change custom font to bold italic in java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Typeface font = Typeface.createFromAsset(getAssets(), "fonts/bebas_neue_regular.ttf");

        TextView tvNormal = (TextView) findViewById(R.id.normal);
        tvNormal.setTypeface(font);

        TextView tvBold = (TextView) findViewById(R.id.bold);
        tvBold.setTypeface(font, Typeface.BOLD);

        TextView tvItalic = (TextView) findViewById(R.id.italic);
        tvItalic.setTypeface(font, Typeface.ITALIC);


        TextView tvBoth = (TextView) findViewById(R.id.boldItalic);
        tvBoth.setTypeface(font, Typeface.BOLD_ITALIC);
    }
}

Tags:

Java Example