Home > Mobile >  How to make status bar and navigation bar transparent using xml file
How to make status bar and navigation bar transparent using xml file

Time:03-08

I'm doing a project that needs the status bar and the navigation bar to be transparent.

I have made the status bar transparent but I am not able to do the same with the navigation bar.

Can anyone help me with this problem. thank

I have set a style like this :

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme">
    <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:navigationBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

note:I just did it in the style.xml file because I already have a complete version that uses the flag

CodePudding user response:

in activity class onCreate method put this code

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        View decorView = window.getDecorView();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
        window.setStatusBarColor(Color.TRANSPARENT);
    }

CodePudding user response:

using navigation or status bar background color code #00000000 or android:background="?android:attr/selectableItemBackground" these can transparent background like button,etc... hope it will work

  • Related