2014-09-12 3 views
1

이 테마를 구현하는 방법에 대한, 내 사용자 정의 스타일이 오버라이드 (override) 시스템 스타일이상한 충돌 "android.view.InflateException는 : 바이너리 XML 파일 라인 # 9 : 오류 팽창 클래스 <unknown>"선언 - styleable

테마를 방지하기 위해 속성을 정의했다. XML

<declare-styleable name="MyThemeBase"> 
    <attr name="myTextColorHighlight" format="reference|color"/> 
</declare-styleable> 

<style name="MyThemeBase" parent="@style/Theme.AppCompat.Light"> 
    ... 
</style> 

<style name="MY.Theme.AppCompat.Light.Orange" parent="SCThemeBase"> 
    <item name="myTextColorHighlight">@color/textcolor_highlight_orange</item> 
</style> 

<style name="MY.Theme.AppCompat.Light.Blue" parent="SCThemeBase"> 
    <item name="myTextColorHighlight">@color/textcolor_highlight_blue</item> 
</style> 

나는 또한 정의 된 사용자 정의 TextAppearance styles.xml

<style name="My.TextAppearance.Medium" parent="@android:style/TextAppearance.Medium"> 
    <!-- this line caused crash --> 
    <item name="android:textColor">?attr/myTextColorHighlight</item> 

    <!-- this worked --> 
    <!--<item name="android:textColor">@color/textcolor_highlight_orange</item>--> 
</style> 

레이아웃 xmls에서 MY.TextAppearance.Medium 스타일보다 위에 언급 된 일부 TextViews는 모든 것이 그렇게 좋았습니다. ListView가 있었다 하나의 텍스트 뷰를하고 설계하는 동안하지만 사고를 가지고, 스택 트레이스는 가장 이상한

android.view.InflateException: Binary XML file line #9: Error inflating class <unknown> 
     at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691) 
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
     at com.xxx.yyy.MyListAdatper.getView(MyListAdatper.java:46) 

은 같은 스타일의 다른 TextViews 내가이 우연히 왜 아무 생각도 없어

좋은이었다. 일부 디버깅을 통해 방금 attr 참조 대신 직접 색상을 사용하는 경우에만 작동한다는 것을 알았습니다 (위 styles.xml의 주석을 확인하십시오). My.TextAppearance.Medium의 정의입니다.

누구든지 도움을받을 수 있습니까? 감사.

+0

'? attr/myTextColorHighlight'이 (가) '? attr/textColorHighlight'가 아니어야합니까? –

+0

@Kenny, myTextColorHighlight를 선언했습니다. – fifth

+0

아, 죄송합니다. 내 사과. –

답변

0

나는이 문제가 당신의 접근 방식이라고 생각합니다. 당신이 정의한 것은 styleable, 즉 다른 값을 할당 할 수있는 커스텀 애트리뷰트이다.

대신 원하는 것은 속성 참조입니다.이 참조는 테마에 따라 다른 값을 할당 할 수있는 상수 ID입니다. 대신이 들어

:

<declare-styleable name="MyThemeBase"> 
    <attr name="myTextColorHighlight" format="reference|color"/> 
</declare-styleable> 

그냥 넣어 :

입니다
<attr name="myTextColorHighlight" format="reference|color"/> 

, 당신은 단지 "선언 - styleable"래퍼를 제거해야합니다. 그것은 문제없이 작동해야합니다.

관련 문제