안드로이드 디자인

[Android] 타이틀바/액션바/상태바 숨기기 및 색상 변경

나도개발자 2020. 8. 19. 01:32

미리보기

타이틀바/액션바 숨기기 및 상태바 색상 바꾸기가 적용된 모습

 

타이틀바/액션바/상태바 숨기기

- windowNoTitle : 타이틀바

  • true : 숨기기
  • false : 보이기(기본값)

- windowActionBar : 액션바

이 옵션을 적용하거나 style의 parent에서 "Theme.AppCompat.Light.NoActionBar"로 설정하여 숨길 수 있다.

  • true : 보이기(기본값)
  • false : 숨기기

- windowFullscreen : 상태바

이 속성을 적용시키면 adjustResize 속성이 적용되지 않는다.

  • true : 숨기기
  • false : 보이기(기본값) 

[res] - [values] - style.xml

<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="windowNoTitle">true</item> <!-- 타이틀바 숨기기 -->
        <item name="windowActionBar">false</item> <!-- 액션바 숨기기 -->
        <item name="android:windowFullscreen">true</item> <!-- 상태바 숨기기 -->
    </style>
</resources>

 

한 번에 모든 레이아웃 배경 색상 변경

안드로이드 배경 색상은 완전한 흰색이 아닌 아이보리색 같은 색이다. 각 레이아웃마다 배경 색상을 지정해줄 필요 없이 style.xml 파일에서 한 번에 변경이 가능하다. (코드는 아래 함께 첨부)

 

- windowBackground : 레이아웃 배경 색상 바꾸기

 

상태바 색상 바꾸기, 상태바 아이콘 색상 변경

- colorPrimaryDark : status bar(상태바) 색상

- windowLightStatusBar : status bar(상태바) 아이콘 색상

  • true : 흰색
  • false : 검정색

속성을 복사, 붙여넣기하면 오류가 날 것이다. 당황하지 말고 Alt+Enter를 눌러주면 resources에xmlns:tools="http://schemas.android.com/tools" 라는 코드가 삽입되며 오류가 사라진다.

 

[res] - [values] - style.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    	<item name="android:windowBackground">@color/white</item> <!-- 배경 색상 -->
        <item name="colorPrimaryDark">@color/white</item> <!-- 상태바 색상 -->
        <item name="android:windowLightStatusBar" tools:targetApi="23">true</item> <!-- 상태바 아이콘 색상 -->
    </style>
</resources>

 

 

 

본 작성자는 안드로이드 개발을 공부하고 있는 학생으로 피드백 및 질문을 환영합니다. 그러나 무단복제 및 배포는 정중하게 사양하고 있으며, 참고 사이트로 링크를 남기실 때는 동의를 구해주시기 바랍니다.

반응형