gpt4 book ai didi

android - 模态底部工作表更改状态栏颜色

转载 作者:行者123 更新时间:2023-11-29 16:55:36 26 4
gpt4 key购买 nike

标准 BottomSheetDialogFragment 将我的状态栏颜色更改为丑陋的绿色,并且我无法将其更改为任何其他颜色。尝试过this但它不起作用。有什么想法吗?

2 : Status bar screenshot

这是我的对话框类:

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");

最佳答案

我使用以下方法解决了这个问题:

dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

关于android - 模态底部工作表更改状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45065017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com