2013-02-14 68 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); 
    } 
相關問題