在我的操作栏中加载自定义字体之前滞后

时间:2014-01-18 09:40:07

标签: android android-actionbar

我想为我的操作栏标题使用自定义字体,所以这里是代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);

        setActionBarCustomFont();
    } 
private void setActionBarCustomFont(){
        this.getActionBar().setDisplayShowCustomEnabled(true);
        this.getActionBar().setDisplayShowTitleEnabled(false);
        this.getActionBar().setDisplayShowHomeEnabled(false);

        Typeface customTypeFace = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");

        View v = getLayoutInflater().inflate(R.layout.title_view, null);

        TextView actionBarTitleView = ((TextView)v.findViewById(R.id.title));
        actionBarTitleView.setText(this.getTitle());
        actionBarTitleView.setTypeface(customTypeFace);

        this.getActionBar().setCustomView(v);
    }

问题是在加载我的字体之前存在延迟。当我启动我的应用程序时,操作栏图标被加载,文本以默认字体显示,并且仅在我的自定义字体加载几次后才显示。

如何避免这种滞后?

0 个答案:

没有答案