Java/Android

attrs.xml 파일에 정의 된 내용 사용하기

체리필터 2013. 11. 2. 16:39
728x90
반응형

스마트폰에서 Pull to Refresh를 사용하는 것은 매우 흔해진 일이고, 그래서 안드로이드에서도 Pull to Refresh를 구현한 오픈소스가 있다.

현재 프로젝트에서는 handmark.pulltorefresh liabrary를 이용하는데 리스트를 당겼을 시 나오는 폰트의 색깔을 변경하는 것이 어떻게 하는 것인지 몰랐다.

해당 라이브러리의 소스를 분석해서 찾아 들어가 보니 아래와 같은 소스를 만날 수 있었다.

 

// Text Color attrs need to be set after TextAppearance attrs

if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {

    ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);

    if (null != colors) {

        setTextColor(colors);

    }

 }

 

R.styleable에 정의된 PullToRefresh_ptrHeaderTextColor를 이용한다는 것이었다.

R.styleable이 뭐하는 것인지 또 구글링...

요놈은 attrs.xml 파일에 정의된 내용을 사용하는 것이라는 결론을 내렸다.

attrs.xml 파일 안을 뒤져보니 아래와 같이 ptr에 정의된 내용이 나오더라.

 

<declare-styleable name="PullToRefresh">

<!-- A drawable to use as the background of the Refreshable View -->
<attr name="ptrRefreshableViewBackground" format="reference|color" />

<!-- A drawable to use as the background of the Header and Footer Loading Views -->
<attr name="ptrHeaderBackground" format="reference|color" />

<!-- Text Color of the Header and Footer Loading Views -->
<attr name="ptrHeaderTextColor" format="reference|color" />

<!-- Text Color of the Header and Footer Loading Views Sub Header -->
<attr name="ptrHeaderSubTextColor" format="reference|color" />

 

ptrHeaderTextColor, ptrHeaderSubTextColor라는 속성을 가진 놈을 어떻게 잘 요리하면 색이 바뀔 듯도 한데... 정확히 사용법을 몰라 또 구글링...

결론은 아래와 같이 layout xml에 정의하면 된다.

 

 <com.handmark.pulltorefresh.library.PullToRefreshGridView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"

......

 ptr:ptrHeaderTextColor="#336699"
 ptr:ptrHeaderSubTextColor="#336699"/>

 

ptr이란 namespace를 정의한 후 해당 속성을 정의하면 된다.

바로 빌드하고 테스트 해 보니 제대로 나오는 것을 확인 ^^

 

오늘 알게 된 내용도 나 혼자 잊어 버리지 않고자 적어둔 내용이므로, 정리가 매우 불성실하다 ^^

728x90
반응형