How to reference a theme attribute in a style?

后端 未结 2 641
慢半拍i
慢半拍i 2021-02-02 00:52

I\'ve got a following problem. I want to customize appearance of row in a list, but exception is thrown during inflating.

piece of code in style.xml

<         


        
相关标签:
2条回答
  • 2021-02-02 01:25

    The problem has been solved. I used application context to create adapter, when I changed context to activity the problem disappeared.

    0 讨论(0)
  • 2021-02-02 01:32

    Try to create the themes.xml file and add the below lines in it.

    Themes.xml

    <style name="Theme">
       <item name="item_shadowColor">@style/item_label</item>
    </style>
    

    attrs.xml
    Change the the format="reference" in your attrs.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <attr name="item_shadowColor" format="reference" />
    </resources>
    

    styles.xml

    <style name="AppTheme.Main">     
        <item name="item_shadowColor">#000000</item>        
    </style>
    
    <style name="item_label">    
        <item name="android:shadowColor">#F240FF</item>        
    </style>
    

    Then after define your style to the TextView as below:

    <TextView
        android:id="@id/title"
        style="@style/item_label"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    
    0 讨论(0)
提交回复
热议问题