안드로이드 학습(Kotlin)

6. Android Theme (테마)

리저브콜드브루 2025. 2. 3. 13:47
728x90
반응형

Theme

  • 앱의 전체적인 UI 스타일을 일관되게 정의하는 요소
  • 버튼, 텍스트, 배경색, 폰트 등 앱 전반에 걸쳐 일관된 디자인을 적용할 수 있다.
  • 앱의 사용자 경험(UX)를 개선하고 유지보수성을 높이기 위해 중요하다.

Theme와 Style의 차이

항목 Theme Style
정의 앱 전체 또는 Activity, View의 전반적인 디자인을 정의 개별 View(버튼, 텍스트 등)에 적용되는 디자인 속성
적용 범위 앱 전체, Activity 단위 View 단위
적용 방법 AndroidManifest.xml 또는 코드로 적용 XML 레이아웃 파일에서 직접 적용
예시 다크 모드 버튼 색상, 폰트 크기

Theme의 주요 속성

속성 설명
colorPrimary 앱의 기본 색상 (툴바, 액션바 배경)
colorPrimaryVariant 기본 색상의 변형
colorSecondary 강조 색상 (FAB, 체크박스 등)
colorBackground 기본 배경색
android:windowBackground 전체 윈도우의 배경색
android:textColor 기본 텍스트 색상
android:fontFamily 기본 폰트 설정

Theme 정의

  • res/values/styles.xml 파일에서 정의
  • 색상, 폰트, 배경, 버튼 모양 등 앱 전반의 디자인 요소를 설정
<resources>
    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <item name="android:windowBackground">@color/white</item>
    </style>
</resources>
  • parent 속성은 상속할 기본 테마를 정의 (Material Components 테마 사용)
  • item 요소로 색상, 폰트, 배경 등을 설정

Theme 적용 예시

앱 전체에 테마 적용(AndroidManifest.xml)

<application
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" />
</application>

 

 

특정 Activity에만 테마 적용

<activity
    android:name=".SettingsActivity"
    android:theme="@style/SettingsTheme" />

 

 

코드에서 동적으로 테마 적용

setTheme(R.style.AppTheme)
setContentView(R.layout.activity_main)
  • Activity onCreate() 호출 전에 setTheme()을 호출해야 적용됨
728x90
반응형