2014-04-18 52 views
1

我的應用程序中有一些活動。它在AndroidManifest.xml中有主題android:theme="@android:style/Theme.Holo.Light.NoActionBar" 。此活動是一個片段的容器,它只有<fragment>標籤。 於是,我開始另一個片段從先用這個代碼:從片段更改活動主題和徽標,附加到android.R.content

Fragment newFragment = new WelcomeStep2Fragment(); 
      FragmentTransaction transaction = getFragmentManager().beginTransaction(); 

      transaction.replace(android.R.id.content, newFragment); 
      transaction.addToBackStack(null); 

      transaction.commit(); 

因此,在第二個片段我想顯示的ActionBar。我有我自己的主題

<style name="AppThemeColoredActionBar" parent="@android:style/Theme.Holo.Light"> 

但是,當我寫

getActivity().setTheme(R.style.AppThemeColoredActionBar); 
    getActivity().getActionBar().setLogo(getResources().getDrawable(R.drawable.ic_back_on_action_bar)); 

這是行不通的。但是,我知道這段代碼無法工作。那麼,是否有辦法從第二個片段中更改活動樣式和徽標?

回答