Android Full Height DialogFragment with transparent status bar color how to change status bar text color?

607 Views Asked by At

I implement the DialogFragment below. I want the status bar color to be transparent, the status bar text color to be dark in light theme. Also the text color need to be white in dark theme.

How can I implement it?

However, I know that when clear dim flag, it can solve the question above. But I need 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);
        }
    }
}


enter image description here

1

There are 1 best solutions below

0
Daniel Pína On

Add this style.

<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>

Then add this style to your activity in app AndroidManifest.xml.

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