I have developed an android app a few months ago that targets the API 19 and also is compiled with API 19. One of the things that I did is that I changed the font of Action Bar Title and also the color dynamically based on the scrolling and other factors. For that I have used the method below:
// change the font of action bar
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView abTitle = (TextView) findViewById(titleId);
Typeface typeFace = Typeface.createFromAsset(getAssets(),
"fonts/Lato-Regular.ttf");
abTitle.setTypeface(typeFace);
//this part is dynamic based on the calculation of ratio
abTitle.setTextColor(getResources().getColor(R.color.white));
abTitle.setAlpha(ratio);
Now I have switched to Material Desing
and I have used AppCompat v7: 22+
. But when I run the application it crashes and gives me a NullPointerException
in the following line:
abTitle.setTypeface(typeFace);
So it seems that it gets the id of the title but it cannot find the TextView
Any Idea or other ways to achieve this would be more than appreciated.