current position:Home>After the Android 11 navigationbarcolor is set to be transparent, there is always a layer of gray? Is there a solution?

After the Android 11 navigationbarcolor is set to be transparent, there is always a layer of gray? Is there a solution?

2022-01-27 03:35:37 CSDN Q & A

Android11 navigationBarColor After setting transparency , There's always a gray layer ? Is there a solution ?
The way to set transparency is

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            Window window = getWindow();            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);//FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS Represents the background responsible for drawing the status bar ,            //  When this is set flag, The system status bar will become transparent , At the same time, the corresponding area will be filled with the following two lines             window.setStatusBarColor(Color.TRANSPARENT);// The top navigation bar is transparent             window.setNavigationBarColor(Color.TRANSPARENT);// The bottom status bar is transparent         }

Later I saw someone say Android7.0 After the DecorView The source code has been added in , Need to get mSemiTransparentStatusBarColor This attribute , Then I tried

try {    DecorView decordView = (DecorView) getWindow().getDecorView();     // obtain DecorView example     Field field = DecorView.class.getDeclaredField("mSemiTransparentStatusBarColor");  // Get a specific member variable     field.setAccessible(true);   // Set accessibility to this property     field.setInt(decordView, Color.TRANSPARENT);  // Modify attribute values } catch (Exception e) {    e.printStackTrace();}

But found DecorView This class can't be found , This method also failed .
Is there any other solution ?




Refer to the answer 1:
    add to  <item name="android:enforceNavigationBarContrast">false</item> After the solution 



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270335324568.html

Random recommended