Far*_*deh 2 android android-theme android-fragments navigation-drawer android-styles
我有一个ActionBarActivity其中有导航抽屉的片段。当按下导航抽屉中的某个项目时,它会启动相应的片段。在每个片段中,该onCreate()方法如下所示:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTheme(R.style.AppTheme);
setHasOptionsMenu(true);
}
Run Code Online (Sandbox Code Playgroud)
然而,每个片段所应用的主题都不同。
我注意到该方法似乎没有更改我引用的 中声明的 或 状态栏setTheme()的颜色:ActionBarstyles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/brand_red_primary</item>
<item name="colorPrimaryDark">@color/brand_red_primaryDark</item>
<item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
同样,我的活动中的不同片段有不同的样式colorPrimary和不同的属性。colorPrimaryDark
因此,该setTheme()方法不会更改状态ActionBar栏或状态栏的颜色,但它确实会更改一些内容,例如列表视图中回拉功能的颜色。
我是否遗漏了什么,或者我需要做什么来setTheme()更改ActionBar状态栏颜色?
我尝试了此处发布的解决方案,但它给出的结果与我之前尝试过的结果完全相同(使用setTheme())。
您需要在 super.onCreate(..) 之前调用 setTheme(..),它对我有用:
setTheme(R.style.YourThemeName);
super.onCreate(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)