Is it possible to add a custom property into a style in an android resource?

前端 未结 2 1975
遇见更好的自我
遇见更好的自我 2021-02-04 00:39

I\'m a using a view flow component into my project, which allows the dev to override some attributes, like that :



        
2条回答
  •  既然无缘
    2021-02-04 01:26

    Android Application

    If you are not using Android Libraries, then here is what you can do:

    1. Define custom styleable attribute (I guess you've already done that).
    2. Do not use your namespace prefix in style items (namespace defaults to current app's namespace).

    Example:

    In attrs.xml:

    
    
                
    
    

    In styles.xml:

    
            
                
    
    

    Android Library

    If custom attribute comes from Android Library, you can still use described approach. It theoretically should work, because Android Library's namespace is the same as application's (from aapt tool perspective during the build). But I haven't test this myself.


    If you're specifying namespace, it will show error. As far as I know, styles do not support xml namespaces. So this will fail:

    In styles.xml:

    
            
                
    
    

    Parser automatically defaults to current app's AndroidManifest namespace, though you can not specify this namespace explicitly.

提交回复
热议问题