Search code examples
javaandroidandroid-snackbar

Changing typeface of Snackbar


I build Snackbar by this code:

Snackbar sb = Snackbar.make(drawer,  "message", Snackbar.LENGTH_LONG)
       .setAction("action", new View.OnClickListener() {
       @Override
       public void onClick(View view) {

       }
});

Now I want to change the typeface of message and action button but can't find any solution, How to do that?


Solution

  • You can set TypeFace by getting view from Snack bar

    TextView tv = (TextView) (mSnackBar.getView()).findViewById(android.support.design.R.id.snackbar_text);
    Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/font_file.ttf");
    tv.setTypeface(font);
    

    For AndroidX, use resource ID com.google.android.material.R.id.snackbar_text