Android全高DialogFragment与透明状态栏颜色如何改变状态栏文本颜色?

yi0zb3m4  于 2023-01-15  发布在  Android
关注(0)|答案(1)|浏览(556)

我实现了下面的对话框片段。我希望状态栏的颜色是透明的,状态栏的文本颜色是在明亮的主题黑暗。此外,文本颜色需要在黑暗的主题白色。
我该如何实现它?
不过,我知道当清除dim标志时,它可以解决上述问题。但我需要dim!!!dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)

public class MyDialogFragment extends DialogFragment {
    

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        LogUtil.i(TAG, "onCreateDialog() call");

        AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogStyle1)
                .setView(binding.getRoot())
                .create();

        alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = alertDialog.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.height = CustomViewUtil.getScreenH(getContext());
        attributes.width = (int) (CustomViewUtil.getScreenW(getContext()) * 0.8);
        attributes.gravity = Gravity.END;
        window.setAttributes(attributes);
        window.setWindowAnimations(R.style.NavigationDrawerDialogAnimation);
        alertDialog.setCanceledOnTouchOutside(true);
        ...

        return alertDialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        LogUtil.i(TAG, "onStart() call");

        Dialog dialog = getDialog();
        if (dialog != null) {
            Window window = dialog.getWindow();
           
            int width = window.getAttributes().width;
            int height = ViewGroup.LayoutParams.MATCH_PARENT;
            window.setLayout(width, height);
        }
    }
}

guicsvcw

guicsvcw1#

添加此样式。

<style name="TransparentStatusBarWithCustomColorText" parent="Your own app theme">
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>

然后将此样式添加到应用AndroidManifest.xml中的Activity。

<activity
        ...
        android:theme="@style/TransparentStatusBarWithCustomColorText" />

相关问题