2012년 12월 15일 토요일

?attr 지정자

참고: http://developer.android.com/intl/ko/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes

layout 속성 값을 아래와 같이 지정하는 경우가 있다.
?android:attr/TextAppearance.Medium

?attr 지정자를 사용하는 속성 값은 현재 테마에 지정된 값을 사용하라는 의미이다.

예)
res/values/attrs.xml
<resources>
    <attr name="myattr" format="reference" />
</resources>

res/layout/simple_layout.xml
...
<TextView
   style="?attr/myattr"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Text" />
...

res/values/themes.xml
...
<style name="MyTheme" parent="android:Theme.Holo">
    <item name="myattr">@style/MyTextStyle</item>
</style>

<style name="MyTextStyle" parent="android:TextAppearance/>
    <item name="android:textColor">#ffff0000</item>
</style>

AndroidManifest.xml
...
<activity name=".Main" android:theme="@style/MyTheme" />

댓글 없음:

댓글 쓰기