[Android] Style&Theme Android 2011. 12. 16. 14:28
위젯들은 알다 시피 View에서 파생되어 모든 것을 이용한다.

여기서 스타일은 뷰, 테마는 액티비티 단위에 적용되고, 스타일은 문단 스타일, 테마는 데스크탑 테마와 개념상 일치한다.

스타일은 상속을 이용하여 사용 할 수가 있다. 그럴 경우 parent라는 키워드가 붙지만, 그렇지 않을 경우 name만 이용하면 된다.

다음은 그 예이다.

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name = "style1">
        <item name = "android:textColor">#fff000</item>
        <item name = "android:textSize">15pt</item>
    </style>
    <style name = "style2" parent ="@style/style1">
        <item name = "android:textColor">#ff0000</item>
    </style>
</resources>

main.xml

<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        style = "@style/style1"
    />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        style ="@style/style2"
    />
실행을 해 보면 처음의 것은 노란색 글자가 나오고 15pt로 정의 된 글자가 나올 것이다.

두번째는 색상은 재정의 했으나 size는 상속받은 내용 대로 15pt로 동일하게 출력이 되는 것을 확인 할 수 있다.

테마의 경우를 살펴보면 styles.xml에 하나만 추가를 해 주면 된다.

<style name="theme">
        <item name = "android:windowNoTitle">true</item>
</style>

그리고 메니페스트 속성에 테마를 지정을 해 준다.

android:theme="@style/theme"

이 부분을 activity 부분에 추가를 해 주면 된다.

그렇게 하면 윈도우 타이틀이 없어짐을 확인 할 수 있으며, android:theme="@android:style/Theme.Dialog" 처리를 할 경우 대화상자 처럼 나타 날 것이다.