2013-02-14 70 views
2

我无法在屏幕方向更改中保留我的应用程序标签的字体。目前,我正在使用SherlockFragmentActivity的onCreate方法中的以下代码设置字体。应用程序标签字体未在方向更改上保留

titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android"); 
if(titleId == 0) 
    titleId = com.actionbarsherlock.R.id.abs__action_bar_title; 
mAppName = (TextView) findViewById(titleId); 
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/handsean.ttf"); 
mAppName.setTypeface(face); 

打开方向更改字体将恢复为默认值。我尝试使用manifest.xml保存状态,但它没有帮助。它保留除标签字体之外的所有内容。有人可以建议如何做到这一点?

感谢您停下来阅读本文。

回答

1

您是否尝试过设置android:configChanges="orientation"并使用来处理方向更改?

编辑:也解释了here为什么它不起作用。

+0

是的,我尝试过。它不起作用。 – 2013-02-14 23:05:17

+0

我相信杰克在那篇文章中的评论总结了一切。谢谢!! – 2013-02-15 02:53:32

0
**Yes we can do this. 

Override onConfigurationChanged 
set the action bar title inside a handler with a delay of 200.** 

@Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       //your code to set the action bar title 
       setActionBarTitle(title); 
      } 
     }, 200); 
    } 
相关问题