안드로이드 개발/개발팁

상태바,하단의 소프트키 가려지는 현상 해결하기

Aiden96 2025. 8. 26. 10:20

액티비티의 onCreate() 레이아웃호출 위에 삽입 

 // 상태바 아이콘을 밝게(흰색) 변경
        WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
        getWindow().setStatusBarColor(getResources().getColor(R.color.gray));//본인이 설정 

        // 상태바 아이콘을 밝게(흰색) 변경
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            WindowInsetsController insetsController = getWindow().getDecorView().getWindowInsetsController();
            if (insetsController != null) {
                insetsController.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                        WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
            }
        } else {
            // API 30 미만 버전 호환성
            WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView()).setAppearanceLightStatusBars(true);
        }

        getWindow().getDecorView().setOnApplyWindowInsetsListener((v, insets) -> {
            int systemBarInsetTop = insets.getSystemWindowInsetTop();
            int systemBarInsetBottom = insets.getSystemWindowInsetBottom();
            v.setPadding(0, systemBarInsetTop, 0, systemBarInsetBottom);
            return insets;
        });