Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing snackbar typeface in androidx

Before migrating to androidx, I used this code to change the typeface of snackbar text:

Snackbar snackbar = Snackbar.make(main_Coordinator, "No Connection", Snackbar.LENGTH_INDEFINITE);
                View view = snackbar.getView();
                TextView textView = view.findViewById(android.support.design.R.id.snackbar_text);
                textView.setTypeface(Typeface.createFromAsset(getAssets(), "Shabnam.ttf"));

But after migrating to androidx I'm getting error for snackbar_text id android.support.design.R.id.snackbar_text it says Cannot resolve symbol design.

And also I am using the new design library com.google.android.material:material:1.0.0

Any help?

like image 642
houman.sanati Avatar asked Feb 01 '19 07:02

houman.sanati


2 Answers

Just refer to the new design library like this -

Snackbar snackbar = Snackbar.make(main_Coordinator, "No Connection", Snackbar.LENGTH_INDEFINITE);
            View view = snackbar.getView();
            TextView textView = view.findViewById(com.google.android.material.R.id.snackbar_text);
            textView.setTypeface(Typeface.createFromAsset(getAssets(), "Shabnam.ttf"));
like image 106
Kartik Shandilya Avatar answered Sep 22 '22 16:09

Kartik Shandilya


Use com.google.android.material.R.id.snackbar_text.

You've migrated to AndroidX, which means the library is different now. So the R that you're referencing needs to come from the new library instead of the old one.

like image 23
Jackey Avatar answered Sep 23 '22 16:09

Jackey