Change status bar text color when primaryDark is white

前端 未结 8 1271
自闭症患者
自闭症患者 2021-01-30 06:17

I am trying to reproduce the behaviour of Google Calendar application:

but I have not found a way to change the status text color. If i set the colorPrimaryDark as whit

相关标签:
8条回答
  • 2021-01-30 06:43

    As previous, the SYSTEM_UI_FLAG_LIGHT_STATUS_BAR do the work in my case, don't forget to set for higher than API 22.

    add this to oncreate after the setContentView:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
    
    0 讨论(0)
  • 2021-01-30 06:44

    Try this once.

    In your activity onCreate() method, paste the following code.

    try {
            if (android.os.Build.VERSION.SDK_INT >= 21) {
                    Window window = getWindow();
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.setStatusBarColor(ContextCompat.getColor(this, R.color.color_red));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    

    Note: color_red - is the status bar colour.

    0 讨论(0)
  • 2021-01-30 06:46

    you can do that programmatically like this answer

    just add this

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    
    0 讨论(0)
  • 2021-01-30 06:47
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//  set status text dark
    
    getWindow().setStatusBarColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimaryDark));// set status background white
    

    It works for me

    0 讨论(0)
  • 2021-01-30 06:50

    In your activity onCreate() method, paste the following code after the setContentView(R.layout.activity_generic_main);

    Here is the sample code below.

    public class GenericMain extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_generic_main);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    
        }
    }
    
    0 讨论(0)
  • 2021-01-30 06:50

    Try this if not splash page

    getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getActivity().getWindow().setNavigationBarColor(ContextCompat.getColor(context, R.color.white));
    getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(context, R.color.white));
    
    0 讨论(0)
提交回复
热议问题