Change status bar color with AppCompat ActionBarActivity

后端 未结 7 1642
一个人的身影
一个人的身影 2020-11-29 17:04

In one of my Activities, I changed the Toolbar color using Palette. But on 5.0 devices using ActionBarActivity the status bar color i

7条回答
  •  猫巷女王i
    2020-11-29 17:30

    I'm not sure I understand the problem.

    I you want to change the status bar color programmatically (and provided the device has Android 5.0) then you can use Window.setStatusBarColor(). It shouldn't make a difference whether the activity is derived from Activity or ActionBarActivity.

    Just try doing:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.BLUE);
    }
    

    Just tested this with ActionBarActivity and it works alright.


    Note: Setting the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag programmatically is not necessary if your values-v21 styles file has it set already, via:

        true
    

提交回复
热议问题