2
我有活动,我在用户触摸事件上使用了五个片段。我想为3个片段设置状态栏颜色,其他两个片段没有状态栏。如何更改片段的状态栏颜色?
如果我在一个片段的onCreateView方法中使用下面的代码,它会更改活动的状态栏,并且我使用getActivity()方法获得所有片段的白色。所以我正在寻找碎片的解决方案。
getActivity().getWindow.setStatusBatColor(Color.White);
我也尝试在style.xml中设置我的主题,并将其应用于xml中的fragemnts根布局,但它也不能正常工作。
styles.xml
<style name="StatusBarColor" parent="AppBaseTheme">
<item name="android:statusBarColor">#F5F5F5
</item>
</style>
fragment1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/StatusBarColor"
android:background="@color/home_bg_white"
tools:context="mycontext">
预先感谢您的帮助。
我想改变片段状态栏,所以在片段类中它不允许我添加getWindow方法,那就是问题。 –
您的片段必须是活动的一部分。你可以用活动的方法编写这段代码,然后从你的片段中调用它。它会解决你的问题。 –
使用我在我的编辑部分 –