白色导航栏与灰色图标

6
如何在我的Android应用中获得这种样式?白色导航栏和灰色图标。一个例子是打开应用程序抽屉时。 enter image description here 我尝试了很多选项,但都没有成功。 应用的minSdkVersion为21,棒棒糖。
我看到了这个解决方案,但我没有成功应用它: 状态栏变白,不显示其后面的内容
2个回答

11

对于API >= 23

尝试:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); 

OR的样式:

<item name="android:windowLightStatusBar">true</item>
<item name="colorPrimary">@color/colorWhite</item>
<item name="colorPrimaryDark">#colorPrimaryDak</item>
<item name="colorAccent">@color/colorAccent</item>

针对 API < 23

在 v21/style 下声明此内容。

<item name="colorPrimaryDark" tools:targetApi="23">@color/colorPrimary</item> // white
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>

更新:

<item name="colorPrimaryDark">@color/colorPrimary</item> // white
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>

2
21,我在上面提到过。它似乎不起作用,通知栏变成了灰色,而不是白色 :( - Sergio76
2
好的,所以在colorPrimaryDark中不需要写入tools:targetApi="23",因为它也适用于较低版本。对于android:windowLightStatusBar来说是很好的。 - user2756345
1
此解决方案不适用于小于23的设备。 - Abdelrhman Talat
2
我试过了,但它并没有起作用,你能解释一下为什么会这样吗? - Abdelrhman Talat
18
我不明白谁在为这个答案投票。这个解决方案可能不适用于21-22版本的API。 - Sergei S
显示剩余16条评论

1

你无法做到。API 21-22未提供此功能。

但是,您可以将其变为黑色

getWindow().setStatusBarColor(Color.BLACK);

完整示例:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            getWindow().setStatusBarColor(Color.BLACK);
        }

    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接