You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 15(API 35)Edge-to-Edge模式下搭配导航抽屉与Toolbar时状态栏颜色无法修改为绿色的问题求助

Android 15(API 35)Edge-to-Edge模式下搭配导航抽屉与Toolbar时状态栏颜色无法修改为绿色的问题求助

各位大佬好!我现在卡在Android 15的Edge-to-Edge适配问题上了:整体UI的Edge-to-Edge功能跑起来是正常的,但状态栏的颜色死活没法改成我需要的绿色——之前在Android 13及更低版本,搭配导航抽屉和Toolbar的时候这个绿色状态栏是正常显示的。

我已经对照官方的Edge-to-Edge适配指南,还有Android Developers的相关博客试过各种调整了,但不管怎么改状态栏都出不来想要的绿色,实在没辙了来求助大家!

下面是我目前在用的实现代码:

private void edgeToedge() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
            EdgeToEdge.enable(this);

            WindowInsetsControllerCompat windowInsetsController =
                    ViewCompat.getWindowInsetsController(getWindow().getDecorView());
            if (windowInsetsController == null) {
                return;
            }

            windowInsetsController.setAppearanceLightNavigationBars(true);
            WindowCompat.getInsetsController(getWindow(),getWindow().getDecorView())
                    .setAppearanceLightStatusBars(true);

            WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
            ViewCompat.setOnApplyWindowInsetsListener(toolbar, new OnApplyWindowInsetsListener() {
                @NonNull
                @Override
                public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
                    // Retrieve the insets for the system bars (status bar, nav bar, etc.)
                    Insets systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                    // Update layout params: add a top margin equal to the status bar height.
                    ViewGroup.LayoutParams lp = v.getLayoutParams();
                    if (lp instanceof ViewGroup.MarginLayoutParams) {
                        ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) lp;
                        marginParams.topMargin = systemBarsInsets.top;
                        v.setLayoutParams(marginParams);
                    }
                    // Alternatively, you can update padding if that better suits your design:
                    // v.setPadding(v.getPaddingLeft(), originalPaddingTop + systemBarsInsets.top,
                    //              v.getPaddingRight(), v.getPaddingBottom());

                    return insets;
                }
            });

        }
    }

附上当前的状态栏效果截图,方便大家直观看到问题:

当前状态栏显示效果

备注:内容来源于Stack Exchange,提问作者Ritu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:09:50