Changing typeface of Snackbar

user5510211 picture user5510211 · Nov 4, 2015 · Viewed 9.9k times · Source

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?

Answer

Ashish Agrawal picture Ashish Agrawal · Nov 4, 2015

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