Android color selector doesn't work with custom attributes

后端 未结 3 1697
误落风尘
误落风尘 2020-12-06 00:10

I\'ve got in attrs.xml

 
    
    
    <         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 00:44

    You cannot reference ?attr/ when choosing colors for a selector. What you can do, if you want per-theme colors in your selector, is create multiple selectors which reference @color/ and @drawable/, and then have a "reference" attr which associates one of the selectors with the given style.

    You then have to set the text color like

    android:textColor="?attr/forground_to_background"
    

    I believe the text was always red because Android was interpreting the attr's integer value as a color (red), rather than using it as a lookup for what you actually wanted.

提交回复
热议问题