使用AppCompat v7更改操作栏标题的字体和颜色

时间:2015-05-08 08:31:14

标签: android android-actionbar appcompat-v7-r22.1 appcompatactivity

几个月前我开发了一个针对API 19的Android应用程序,并且还使用API​​ 19进行编译。我做的一件事就是我改变了Action Bar Title的字体以及动态的颜色滚动和其他因素。为此,我使用了以下方法:

// 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);

现在我已切换到Material Desing,我使用了AppCompat v7: 22+。但是当我运行应用程序时,它会崩溃并在下一行中给我一个NullPointerException

abTitle.setTypeface(typeFace);

所以它似乎获得了标题的ID,但找不到TextView

任何想法或其他方法可以实现这一点。

0 个答案:

没有答案
相关问题