如何在Android中将状态栏颜色更改为透明并将其上的项目更改为绿色?

时间:2019-02-20 06:59:25

标签: android android-coordinatorlayout

我要使状态栏如下图所示。

how to change colors of my status bar according to this pic

我尝试了一些方法,但没有一个起作用。有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
    }
    super.onCreate(savedInstanceState);

并将此行添加到主题

<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>