question mark(?)를 이용하여 xml에서 현재 테마에 맞춰 값을 설정 할 수 있다.
?android:textColorSecondary
?android:attr/textColorSecondary
동일한 의미이며 values/attrs.xml에 설정된 attribute를 이용하는데 이때 해당하는 attribute에 대한 세부 설정은 theme_base.xml에 설정되어있다.
android-support-v7-appcompat
를 예시로 들면
•res/layout/abc_action_bar_home.xml
android:src="?attr/homeAsUpIndicator"
•res/values/attrs.xml
<!-- Specifies a drawable to use for the 'home as up' indicator. -->
<attr name="homeAsUpIndicator" format="reference"/>
•res/values/themes_base.xml
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_holo_dark</item>
위와 같은 방식으로 사용하고 있다.
Referencing style attributes
A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@
), use a question-mark (?
), and the resource type portion is optional. For instance:
?[<package_name>:][<resource_type>/]<resource_name>
For example, here's how you can reference an attribute to set the text color to match the "primary" text color of the system theme:
<EditText id="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:text="@string/hello_world" />
Here, the android:textColor
attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary
style attribute as the value for android:textColor
in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary
)—you can exclude the attr
type.
출처: http://developer.android.com/intl/ko/guide/topics/resources/accessing-resources.html
http://stackoverflow.com/a/4771871/5182144
'Programming Study > Android' 카테고리의 다른 글
[Android] xml에서 xmlns:android=“http://schemas.android.com/apk/res/android” 의 의미 (0) | 2015.08.01 |
---|---|
[Android] xml layout의 tools attribute (0) | 2015.08.01 |