Standard BottomSheetDialogFragment changes my status bar color to this ugly greenish thing and I can't change it to any other color. Tried this but it doesn't work. Any thoughts?
This is my dialog class:
public class BottomSheetExample extends BottomSheetDialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet, container, false);
// Code below only changes status bar color to black after bottom
// sheet closes, not while it's open like it should
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.colorBlack, null));
}
else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.colorBlack));
}
}
}
return v;
}
}
and this is bottom_sheet layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Sheet Example" />
</LinearLayout>
I call it from MainActivity like this:
BottomSheetDialogFragment dialogFragment = new BottomSheetExample();
dialogFragment.show(getSupportFragmentManager(), "tag");
I solved the problem by using:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);