【发布时间】:2017-07-12 18:22:48
【问题描述】:
Standard BottomSheetDialogFragment 将我的状态栏颜色更改为这种难看的绿色,我无法将其更改为任何其他颜色。试过this,但它不起作用。 有什么想法吗?
这是我的对话类:
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;
}
}
这是 bottom_sheet 布局文件:
<?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>
我这样从 MainActivity 调用它:
BottomSheetDialogFragment dialogFragment = new BottomSheetExample();
dialogFragment.show(getSupportFragmentManager(), "tag");
【问题讨论】: