0

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.

Xhulio
  • 581
  • 7
  • 26
  • you can check this link http://stackoverflow.com/questions/8607707/how-to-set-a-custom-font-in-the-actionbar-title/15181195#15181195 – saurabh64 May 08 '15 at 08:40
  • check out.http://stackoverflow.com/a/5881739/1092844 – devcelebi May 08 '15 at 08:42
  • you can try this library so you can avoid using setTypeFace. It is using android support library v22.1 so I think it won't be a problem in your project. [link](https://github.com/chrisjenx/Calligraphy/tree/master/calligraphy) – Ace Siena May 08 '15 at 08:43
  • But what about changing the color dynamically based on the scrolling factor? – Xhulio May 08 '15 at 08:47
  • Here is the solutions, I hope this will help you. http://stackoverflow.com/questions/17966350/changing-the-font-of-the-application-title-in-android/21480484#21480484 – Karthikeyan Jul 24 '15 at 10:41
  • Possible duplicate of [AppCompat v7 r21 changing Alpha of the ActionBar's title](http://stackoverflow.com/questions/26572164/appcompat-v7-r21-changing-alpha-of-the-actionbars-title) – Daniele D. Oct 01 '15 at 14:36

0 Answers0